問題描述
我是本機 C++ 的新手.現(xiàn)在,我做到了,當(dāng)我按下鼠標左鍵時,它有一個 for 循環(huán),它執(zhí)行 InvalidateRect 并繪制一個矩形,并在每次迭代時按框大小增加 X.但是,C++ 的繪圖速度和效率比 C# 快得多,它可以立即繪制所有這些.我想要的是它使矩形無效,顯示矩形,等待 50 毫秒,然后繼續(xù)循環(huán).我試過 Sleep(50) 但它仍然等到繪畫完成后再顯示結(jié)果.我也試過 PeekMessage 但它沒有改變?nèi)魏螙|西.任何幫助,將不勝感激.謝謝
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);
}
}
}
這篇關(guān)于DoEvents 等效于 C++?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!