额,还是从一个window程序的基本结构看起吧
Win32程序基本结构
-
注册窗口类别 RegisterClass
-
创建窗口 CreateWindow
-
启动由GetMessage和DispatchMessage构成的事件循环
-
被注册的回调函数 WndProc 负责相应各类事件
#include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("Hello"); HWND hwnd; MSG msg; WNDCLASS wndclass; //fill wndclass wndclass.lpfnWndProc = WndProc; ... RegisterClass(&wndclass); hwnd = CreateWindow( .... ); // creation parameters ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch(message) { case WM_CREATE: return 0; case WM_PAINT: ... return 0; case WM_DESTROY: PostQuitMessage(0);