- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
#include <windows.h>
#include <stdio.h>
class tWnd {
private:
static LRESULT CALLBACK Disp_test_WndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam) // second message parameter
{
switch (uMsg)
{
case WM_TIMER:{
printf("timer\n");
return 0;
}
case WM_PAINT:
// Paint the window's client area.
return 0;
case WM_DESTROY:
return 0;
case WM_HOTKEY:{
} return 0;
//
// Process other messages.
//
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
public:
tWnd() {
WNDCLASSA wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) Disp_test_WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) NULL;
wc.lpszMenuName = "";
wc.lpszClassName = "Test";
if (!RegisterClass(&wc))
return; //cannot register window class
HWND testingWindow = CreateWindowEx(WS_EX_TOPMOST,"Test","topmost",WS_VISIBLE,0,0,200,200,0,0,0,0);
SetTimer(testingWindow,101,500,(TIMERPROC)NULL);
MSG recent;
BOOL result;
while((result=GetMessage(&recent,testingWindow,0,0))&&result!=-1) { //bool can be -1 in MS world
if(recent.message==WM_USER+1) break;
TranslateMessage(&recent);
DispatchMessage(&recent);
}
}
};
int main(int argc, char **argv)
{
tWnd();
return 0;
}
此代码永远不会收到 WM_TIMER 消息。
#include <windows.h>
#include <stdio.h>
class tWnd {
private:
static LRESULT CALLBACK Disp_test_WndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam) // second message parameter
{
switch (uMsg)
{
case WM_TIMER:{
printf("timer\n");
return 0;
}
case WM_DESTROY:
return 0;
case WM_HOTKEY:{
} return 0;
//
// Process other messages.
//
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
public:
tWnd() {
WNDCLASSA wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) Disp_test_WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) NULL;
wc.lpszMenuName = "";
wc.lpszClassName = "Test";
if (!RegisterClass(&wc))
return; //cannot register window class
HWND testingWindow = CreateWindowEx(WS_EX_TOPMOST,"Test","topmost",WS_VISIBLE,0,0,200,200,0,0,0,0);
SetTimer(testingWindow,101,500,(TIMERPROC)NULL);
MSG recent;
BOOL result;
while((result=GetMessage(&recent,testingWindow,0,0))&&result!=-1) { //bool can be -1 in MS world
if(recent.message==WM_USER+1) break;
TranslateMessage(&recent);
DispatchMessage(&recent);
}
}
};
int main(int argc, char **argv)
{
tWnd();
return 0;
}
此代码可以很好地获取 WM_TIMER 消息。
两者之间的唯一区别是 WM_PAINT 消息在第二种变体中是默认处理的。为什么处理 WM_PAINT 会阻止程序接收 WM_TIMER 消息?我该如何解决这个问题?
如果重要的话,我正在使用 MingW w64 (GCC 5.3.0)。
最佳答案
当窗口的无效区域非空时,它会收到 WM_PAINT
消息。 ValidateRect()
的文档中对此进行了说明。 :
The system continues to generate WM_PAINT messages until the current update region is validated.
标准 WM_PAINT
处理程序会验证无效区域(例如通过调用 BeginPaint()
),默认实现会这样做。简单地返回 0
不会验证窗口,并且它会继续接收 WM_PAINT
消息。
WM_TIMER
消息的优先级低于 WM_PAINT
消息。您的窗口消息处理程序永远不会看到计时器消息,因为它一直忙于忽略绘制消息。 WM_TIMER
的文档中对此进行了说明。 :
The
WM_TIMER
message is a low-priority message. TheGetMessage
andPeekMessage
functions post this message only when no other higher-priority messages are in the thread's message queue.
关于c - WM_TIMER 在特定条件下丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44375712/
#include #include class tWnd { private: static LRESULT CALLBACK Disp_test_WndProc( HWN
好吧,我正在使用一个 50 毫秒消逝时间的计时器来制作一些移动文本的动画(从技术上讲,它在文本之间滚动)。 问题是,如果你仔细观察,你会看到文字在闪烁,我希望它不要闪烁.. 所以我不太擅长动画,但是我
我想在标题中显示我的小游戏节目 FPS,但它不应该为每一帧和单个帧重新计算 FPS。我只想每秒刷新一次 FPS 计数器,所以我尝试使用 SetTimer。问题是计时器只在我不移动鼠标或不按住键时才工作
我正在 Visual Studio Express 2013 中编写一个相当简单的 Windows C++ 应用程序,并且在启动时遇到一个问题,即窗口由于 DispatchMessage 处理 WM_
创建窗口后,我启动了一个计时器来做某事。代码如下: SetTimer(hWnd, 1, 40, NULL); //tick each 40 ms. 我追踪到最后一个错误,它是 0。但我无法接收 wm
这里大家都知道,从WinXP到user32.dll出现了MessageBoxTimeout API。 但现在不是使用未记录的 MessageBoxTimeout,而是使用记录的 MessageBox:
在我正在处理的应用程序中,在某些情况下,应用程序运行速度很慢,在这些情况下,我发现我的移动鼠标、计时器/绘画消息没有得到处理。如果我缓慢移动鼠标,我可以无限期地阻止重新绘制窗口! 我发现这是expec
我最初有一个 ActiveX 控件,它注册了一个每隔几秒触发一次的 Windows 计时器(使用 SetTimer())。到目前为止效果很好。现在为了实现全屏模式,我向我的控件添加了一个子窗口,它应该
我遇到过 WinAPI 的奇怪行为,在我看来是这样。在我的程序中,我为窗口设置了一个计时器 ::SetTimer(window_handle, timer_id, 10, NULL); 并在我的窗口过
我正在开发一款客户端需要继续处理 Windows 消息的游戏,否则游戏可能会被利用。为了解决窗口调整大小和拖动事件期间的这个问题,我们有一个每 50 毫秒触发一次的 WM_TIMER 消息,这将重新启
我有一个 MFC Visual C++ 应用程序,它似乎无法在类向导中工作,但是,我有一个 View (CServerView),我想向其添加 WM_TIMER 事件处理程序。 我已经弄清楚如何调用
我是一名优秀的程序员,十分优秀!