我猜它正在以某种方式接收WM_QUIT消息,因为这就是while循环所围绕的(根据proc函数,每当处理WM_DESTROY消息时都会发生这种情况)。
每当我使用PeekMessage而不是GetMessage时,窗口就会自动关闭,我使用PeekMessage以最快的速度运行循环
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if(!CreateMainWindow(hinstance, nCmdShow))
return false;
//this works
while (GetMessage(&msg, (HWND) NULL, 0 , 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
UNREFERENCED_PARAMETER(lpCmdLine);
}
//this automatically closes the window
int done = 0;
while (!done)
{
if (PeekMessage (&msg, NULL, 0 ,0, PM_REMOVE))
{
if (msg.message = WM_QUIT)
done = 1;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
UNREFERENCED_PARAMETER(lpCmdLine);下面是简单的WinProc函数
LRESULT CALLBACK WinProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM
lParam)
{
switch( msg)
{
Case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc ( hWnd, msg, wParam, lParam);
}发布于 2016-04-21 09:56:03
您将WM_QUIT分配给msg.message,而不是比较它。
https://stackoverflow.com/questions/36765436
复制相似问题