可能只是一種粗略的疏忽,但我沒有收到消息循環中的任何WM_SIZE消息。但是,我確實在WndProc中收到了它們。我認爲Windows循環給WndProc發送消息?Windows消息Bizarreness
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
// this message is read when the window is closed
case WM_DESTROY:
{
// close the application entirely
PostQuitMessage(0);
return 0;
} break;
case WM_SIZE:
return 0;
break;
}
printf("wndproc - %i\n", message);
// Handle any messages the switch statement didn't
return DefWindowProc (hWnd, message, wParam, lParam);
}
...現在的消息循環...
while(TRUE)
{
// Check to see if any messages are waiting in the queue
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// translate keystroke messages into the right format
TranslateMessage(&msg);
// send the message to the WindowProc function
DispatchMessage(&msg);
// check to see if it's time to quit
if(msg.message == WM_QUIT)
{
break;
}
if(msg.message == WM_SIZING)
{
printf("loop - resizing...\n");
}
}
else
{
//do other stuff
}
}
另外...如果你自己的窗口用戶界面線程爲自己做了顯式或隱式的SendMessage(例如在處理另一個消息時),它也不會排隊,它會通過一些內部函數並最終調用你的WndProc直接。例如,這就是爲什麼你可以在你的WM_CREATE中使用SetWindowText的原因。 – martona 2010-12-22 03:43:56