C++窗口暂停定时器
我使用 SetTimer
在我的应用程序中创建一个间隔为 50 毫秒的计时器,该计时器将用于绘制一个对象并移动它。
现在我不希望对象在窗口失焦时移动,但我仍然需要对其进行绘制。 每 50 毫秒绘制一次似乎没有必要。性能在这个项目中极其重要。
所以我需要一种方法来暂停计时器,但仍然绘制对象,但最好仅在需要时才绘制。
I'm using SetTimer
to create a timer in my application with an interval of 50ms, this timer is going to be used to draw an object, and move it around.
Now I don't want the object to move when the window is out of focus, but I still need it to be painted.
And having it paint every 50ms, seems unnecessary. And performance is extremely important in this project.
So I need a way to pause the timer, but still draw the object, but preferably only when needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当收到WM_ACTIVATE时,决定是否调用KillTimer或SetTimer。
When you get WM_ACTIVATE, decide whether to call KillTimer or SetTimer.
请注意您最初的问题。
我不会依赖如此低分辨率的 Windows 计时器。这是一条低优先级消息,如果您的程序中正在进行大量繁重的工作,则计时器可能会以您期望的更高间隔被调用。
Just a note aside to you initial problem.
I would not rely on Windows Timer with such low resolution. It's a low priority message and if you have lots of heavy duty things going on in you program, the timer might be invoked at higher intervals that you expect.