代码如下:
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
_RPT0(_CRT_WARN, "PreCreateWindow!\n");
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
_RPT0(_CRT_WARN, "AfterCreateWindow!\n");
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
_RPT0(_CRT_WARN, "AfterShowWindow!\n");
UpdateWindow(hWnd);
_RPT0(_CRT_WARN, "AfterUpdateWindow!\n");
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
_RPT2(_CRT_WARN, "%s->%d\n", GetMsgName(message), message);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
// add by zhangqun;
case WM_GETMINMAXINFO:
{
PMINMAXINFO pMinMaxInfo = (PMINMAXINFO)lParam;
int a = 10;
}
break;
//case WM_NCLBUTTONDOWN:
// _RPT0(_CRT_WARN, "WM_NCLBUTTONDOWN!==============================\n");
// break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
输出如下:
PreCreateWindow!
[2010-05-24 23:35:38]WM_GETMINMAXINFO->36 // 最大值 最小值信息 就是窗口被拖动的最大值与最小值
// CreateWindow函数触发了这四个消息
[2010-05-24 23:35:38]WM_NCCREATE->129 // 非客户区创建
[2010-05-24 23:35:38]WM_NCCALCSIZE->131 // 非客户区计算尺寸
[2010-05-24 23:35:38]WM_CREATE->1 // 窗口创建
AfterCreateWindow!
[2010-05-24 23:35:38]WM_SHOWWINDOW->24
//ShowWindow函数触发了以下的消息
[2010-05-24 23:35:38]WM_WINDOWPOSCHANGING->70
[2010-05-24 23:35:38]WM_WINDOWPOSCHANGING->70
[2010-05-24 23:35:38]WM_ACTIVATEAPP->28
[2010-05-24 23:35:38]WM_NCACTIVATE->134
[2010-05-24 23:35:38]WM_GETTEXT->13
[2010-05-24 23:35:38]WM_ACTIVATE->6
[2010-05-24 23:35:38]WM_IME_SETCONTEXT->641
[2010-05-24 23:35:38]WM_IME_NOTIFY->642
[2010-05-24 23:35:38]WM_SETFOCUS->7
[2010-05-24 23:35:38]WM_NCPAINT->133
[2010-05-24 23:35:38]WM_GETTEXT->13
[2010-05-24 23:35:38]WM_ERASEBKGND->20
[2010-05-24 23:35:38]WM_WINDOWPOSCHANGED->71
[2010-05-24 23:35:38]WM_SIZE->5
[2010-05-24 23:35:38]WM_MOVE->3
AfterShowWindow!
[2010-05-24 23:35:38]WM_PAINT->15
// UpdateWindow函数触发的消息
// AfterUpdateWindow!
[2010-05-24 23:35:38]WM_SYNCPAINT->136
[2010-05-24 23:35:38]WM_GETICON->127
[2010-05-24 23:35:38]WM_GETICON->127
[2010-05-24 23:35:38]WM_GETICON->127
[2010-05-24 23:35:38]WM_NCHITTEST->132
[2010-05-24 23:35:38]WM_SETCURSOR->32
[2010-05-24 23:35:38]WM_MOUSEFIRST->512
[2010-05-24 23:35:38]WM_NCHITTEST->132
[2010-05-24 23:35:38]WM_SETCURSOR->32
[2010-05-24 23:35:38]WM_MOUSEFIRST->512
[2010-05-24 23:35:52]WM_NCHITTEST->132
[2010-05-24 23:35:52]WM_SETCURSOR->32
[2010-05-24 23:35:52]WM_NCMOUSEMOVE->160
//
[2010-05-24 23:35:58]WM_NCHITTEST->132
// 以下为关闭窗口发送的消息
[2010-05-24 23:35:58]WM_SETCURSOR->32
[2010-05-24 23:35:58]WM_NCLBUTTONDOWN->161
[2010-05-24 23:35:58]WM_CAPTURECHANGED->533
[2010-05-24 23:35:58]WM_SYSCOMMAND->274
[2010-05-24 23:35:58]WM_CLOSE->16
[2010-05-24 23:35:58]WM_WINDOWPOSCHANGING->70
[2010-05-24 23:35:58]WM_WINDOWPOSCHANGED->71
[2010-05-24 23:35:58]WM_NCACTIVATE->134
[2010-05-24 23:35:58]WM_ACTIVATE->6
[2010-05-24 23:35:58]WM_ACTIVATEAPP->28
[2010-05-24 23:35:58]WM_KILLFOCUS->8
[2010-05-24 23:35:58]WM_IME_SETCONTEXT->641
[2010-05-24 23:35:58]WM_IME_NOTIFY->642
[2010-05-24 23:35:58]WM_DESTROY->2
[2010-05-24 23:35:58]WM_NCDESTROY->130