1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CHAR:
{
if(wParam==VK_ESCAPE)
SendMessage(hwnd,WM_CLOSE,0,0);
return 0;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC;
char szBuffer[]="Hello, World!";
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,10,10,szBuffer,strlen(szBuffer));
EndPaint(hwnd,&ps);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrev, LPSTR lpszArgument, int nCmdShow)
{
char szClassName[]="Form6";
WNDCLASSEX wc;
MSG messages;
HWND hwnd;
wc.hInstance=hIns;
wc.lpszClassName=szClassName, wc.lpfnWndProc = WndProc;
wc.style = CS_DBLCLKS, wc.cbSize = sizeof (WNDCLASSEX);
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION), wc.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW), wc.lpszMenuName = NULL;
wc.cbClsExtra = 0, wc.cbWndExtra = 0;
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
RegisterClassEx(&wc);
hwnd=CreateWindow(szClassName,szClassName,WS_OVERLAPPEDWINDOW,200,200,444,375,HWND_DESKTOP,NULL,hIns,NULL);
ShowWindow(hwnd, nCmdShow);
while(GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
| |