16,471
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include "resource.h"
//IDR_TEXT1 TEXT DISCARDABLE "text.txt"
HINSTANCE hInst;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
static char *pText;
static HGLOBAL hResource;
switch(message)
{
case WM_CREATE:
hResource = LoadResource(hInst, FindResource(hInst, MAKEINTRESOURCE(IDR_TEXT1), TEXT("TEXT")));
pText = (char*)LockResource(hResource);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
//pText = (char*)LockResource(hResource);
GetClientRect(hwnd, &rect);
DrawTextA(hdc, pText, -1, &rect, DT_EXTERNALLEADING);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
}
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hpreinstance, PSTR cmdline, int showcmd)
{
MSG msg;
static TCHAR *szAppName = TEXT("ya~ha~");
WNDCLASS wndclass;
HWND hwnd;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(0, IDC_ARROW);
wndclass.hIcon = LoadIcon(0, IDI_APPLICATION);
wndclass.hInstance = hinstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = 0;
wndclass.style = CS_HREDRAW|CS_VREDRAW;
hInst = hinstance;
if(!RegisterClass(&wndclass))
{
MessageBox(0, szAppName, TEXT("sth wrong~~"), MB_ICONERROR);
}
hwnd = CreateWindow(szAppName, TEXT("kk"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
0, 0,
hinstance, 0);
ShowWindow(hwnd, showcmd);
UpdateWindow(hwnd);
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
5.结果