gpt4 book ai didi

c++ - WM_TIMER 具有更高的优先级?

转载 作者:太空宇宙 更新时间:2023-11-04 11:24:59 24 4
gpt4 key购买 nike

我想在标题中显示我的小游戏节目 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;

关于c++ - WM_TIMER 具有更高的优先级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27003444/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com