DoEvents等同于C ++? [英] DoEvents equivalent for C++?

查看:920
本文介绍了DoEvents等同于C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是本地c ++的新手。现在,我按下鼠标左键时,它有一个for循环,执行InvalidateRect并绘制一个矩形,并且每次迭代时增加X的框大小。但是,C ++在绘制时比C#快得多,效率高,它立即绘制所有这些。我想要的是它使矩形无效,显示矩形,等待50ms,然后继续循环。我尝试睡眠(50),但它仍然等待,直到绘画完成后才显示结果。我也试过PeekMessage,但它没有改变任何东西。
任何帮助将不胜感激。感谢

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 box size each time it iterates. But, C++ is so much faster and efficient at drawing than C# that, it draws all this instantly. What I would like is for it to invalidate the rectangle, show the rectangle, wait 50ms, then continue the loop. I tried Sleep(50) but it still waits until painting is done before showing the result. I also tried PeekMessage but it did not change anything. Any help would be appreciated. Thanks

推荐答案

DoEvents基本上翻译为:

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);
        }
    }
}

这篇关于DoEvents等同于C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆