#include <windows.h>
const char *ClassName = "MyWindow";
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev,
LPSTR lpCmdLine, int nShowCmd) {
WNDCLASSEX wc;
HWND hWnd;
MSG msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wc.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = ClassName;
wc.lpszMenuName = NULL;
wc.style = 0;
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "Could not register window.", "Error",
MB_ICONEXCLAMATION | MB_OK);
return -1;
}
hWnd = CreateWindowEx(WS_EX_WINDOWEDGE, ClassName, "Basic Window",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 200, 150,
NULL, NULL, hInstance, NULL);
if(hWnd == NULL) {
MessageBox(NULL, "Could not create window.", "Error",
MB_ICONEXCLAMATION | MB_OK);
return -1;
}
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam) {
switch(uMsg) {
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}