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
|
#include <windows.h>
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE thisInst, HINSTANCE prevInst, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HWND hwnd;
WNDCLASSEX wcx;
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_DBLCLKS;
wcx.lpfnWndProc = MainWndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = thisInst;
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcx.hCursor = LoadCursor(NULL, IDC_HAND);
wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcx.lpszMenuName = NULL;
wcx.lpszClassName = "Program";
wcx.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if(!RegisterClassEx(&wcx))
{
return 0;
}
hwnd = CreateWindowEx(0, "Program",
"This is a windows Api program",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, 500, 400, HWND_DESKTOP, NULL, thisInst, NULL);
if(!hwnd)
{
return 0;
}
ShowWindow(hwnd, SW_SHOW);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
}
|