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 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <windows.h>
const char ClassName[] = "winClass";
LRESULT CALLBACK WinProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int CmdShow)
{
WNDCLASSEX winc;
HWND hwnd;
MSG Msg;
winc.cbSize = sizeof(WNDCLASSEX);
winc.style = 0;
winc.lpfnWndProc = WinProc;
winc.cbClsExtra = 0;
winc.cbWndExtra = 0;
winc.hInstance = hInstance;
winc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winc.hCursor = LoadCursor(NULL, IDC_ARROW);
winc.hbrBackground = (HBRUSH) COLOR_WINDOW;
winc.lpszMenuName = NULL;
winc.lpszClassName = ClassName;
winc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if ( !RegisterClassEx(&winc) )
{
MessageBox(NULL, "Failed to register class.", "Error!", MB_ICONEXCLAMATION|MB_OK);
return 0;
}
hwnd = CreateWindowEx(
0, ClassName,
"Test App", WS_OVERLAPPEDWINDOW,
1, 1, 200, 200,
NULL, NULL, hInstance, NULL);
if ( hwnd == NULL )
{
MessageBox(NULL, "Failed to display window.", "Error!", MB_ICONEXCLAMATION|MB_OK);
return 0;
}
ShowWindow(hwnd, CmdShow);
UpdateWindow(hwnd);
while ( GetMessage(&Msg, NULL, 0, 0) > 0 )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
|