Infinite windows message loop

前端 未结 1 1385
难免孤独
难免孤独 2021-01-26 07:15

I have this message loop in my program:

while (true) {
    if (PeekMessage(&msg, window, 0, 0, PM_REMOVE)) {
        if (msg.message == WM_QUIT) {
                   


        
相关标签:
1条回答
  • 2021-01-26 08:13

    You're calling PeekMessage(&msg, window, ...). If window isn't NULL, you'll never get WM_QUIT, because WM_QUIT is not associated with a window.

    Instead, just call PeekMessage/GetMessage with a NULL HWND. DispatchMessage will send it to the right WndProc as necessary. (In general, making GetMessage/PeekMessage filter by HWND is a bad idea.)

    0 讨论(0)
提交回复
热议问题