DoEvents equivalent for C++?(DoEvents 等效于 C++?)
问题描述
我是本机 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++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DoEvents 等效于 C++?
- 近似搜索的工作原理 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- C++ 协变模板 2021-01-01
- 从python回调到c++的选项 2022-11-16