小编hec*_*hec的帖子

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

我的猜测它以某种方式接收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);
Run Code Online (Sandbox Code Playgroud)

这是简单的WinProc功能

LRESULT CALLBACK WinProc ( HWND hWnd, UINT msg, …
Run Code Online (Sandbox Code Playgroud)

winapi message loops

0
推荐指数
1
解决办法
105
查看次数

标签 统计

loops ×1

message ×1

winapi ×1