为什么我无法使用 PeekMessage() 创建成功的消息循环?

why am i unable to create a successful message loop with PeekMessage()?

我猜它以某种方式接收到 WM_QUIT 消息,因为这是 while 循环围绕的内容(根据 proc 函数,每当处理 WM_DESTROY 消息时就会发生)

每当我使用 PeekMessage 而不是 GetMessage 时,window 会自动关闭,我使用 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);
}

您正在将 WM_QUIT 分配给 msg.message 而不是比较它。