DoEvents equivalent for C++?

前端 未结 2 782
眼角桃花
眼角桃花 2020-12-06 13:42

I\'m new to native c++. Right now, I made it so when I press the left mouse button, it has a for loop that does InvalidateRect and draws a rectangle, and increments X by the

2条回答
  •  萌比男神i
    2020-12-06 14:35

    DoEvents basically translates as:

    void DoEvents()
    {
        MSG msg;
        BOOL result;
    
        while ( ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE ) )
        {
            result = ::GetMessage(&msg, NULL, 0, 0);
            if (result == 0) // WM_QUIT
            {                
                ::PostQuitMessage(msg.wParam);
                break;
            }
            else if (result == -1)
            {
                 // Handle errors/exit application, etc.
            }
            else 
            {
                ::TranslateMessage(&msg);
                :: DispatchMessage(&msg);
            }
        }
    }
    

提交回复
热议问题