具有更高优先级的WM_TIMER
WM_TIMER with higher priority?
我希望我的小游戏节目 FPS 出现在标题中,但它不应该重新计算每一帧和单帧的 FPS。我只想每秒刷新一次 FPS 计数器,所以我尝试使用 SetTimer
.问题是计时器只有在我不移动鼠标或按住键的情况下才能工作。据我所知WM_TIMER
是低优先级的消息,因此最后处理。有没有办法在任何其他用户输入消息之前处理WM_TIMER
消息,或者至少另一种创建第二个滴答计时器的方法?
我也尝试使用TimerProc
而不是等待WM_TIMER
,但这也没有用。
如何使用单独的后台线程测量它的简短示例。
int iCount;
int iFramesPerSec;
std::mutex mtx;
// this function runs in a separate thread
void frameCount()
{
while(true){
std::this_thread::sleep_for(std::chrono::seconds(1));
std::lock_guard<std::mutex> lg{mtx}; // synchronize access
iFramesPerSec = iCount; // frames per second during last second that passed
iCount = 0;
}
}
// inside window procedure
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
...
std::lock_guard<std::mutex> lg{mtx}; // synchronize access
++iCount;
EndPaint(hwnd, &ps);
return 0;
相关文章:
- "WM" C++是什么意思?
- 是否需要在 Timer.5 boost::asio 教程中运行新线程?
- libevent是否允许在不同的线程中运行timer/io的回调
- 什么是窗口最大化/最小化/恢复的WM Windows消息
- 请求X11在C或C++中合成WM的图像
- QGraphicsView / Qgraphicsscene Timer事件不起作用
- 使用boost::asio::deadline_Timer实现通用Timer类时出现问题
- 创建 Timer 类时,我应该使用什么数据类型来保存值?(C/C++)
- C++ `Timer` class implementation
- 用c++编写Timer类
- Qt QLCDNumber Timer
- 在 c# 中是否有等效的 boost::timer::cpu_timer
- NachOS timer.cc 构造函数
- 在 c++ 中是否有像 timer 和 timertask 这样的东西,就像 java 一样
- c++计时器,相当于.NET System.Threading.timer
- 开始使用boost-cpu_timer时,错误:“boost::timer::cpu_timer”尚未声明
- 如何从boost::timer::cpu_timer获取以秒为单位的运行时间
- 如果在WM/CE平台中用于卸载,DMProcessConfigXML将关闭正在运行的应用程序
- 如何为一些类(如timer类)编写单元测试
- 如何在c++中创建Timer任务