我是本机 C++ 的新手.现在,我做到了,当我按下鼠标左键时,它有一个 for 循环,它执行 InvalidateRect 并绘制一个矩形,并在每次迭代时按框大小增加 X.但是,C++ 的绘图速度和效率比 C# 快得多,它可以立即绘制所有这些.我想要的是它使矩形无效,显示矩形,等待 50 毫秒,然后继续循环.我试过 Sleep(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++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!