- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我正在处理的应用程序中,在某些情况下,应用程序运行速度很慢,在这些情况下,我发现我的移动鼠标、计时器/绘画消息没有得到处理。如果我缓慢移动鼠标,我可以无限期地阻止重新绘制窗口!
我发现这是expected behaviour :
With the exception of the WM_PAINT message, the WM_TIMER message, and the WM_QUIT message, the system always posts messages at the end of a message queue. This ensures that a window receives its input messages in the proper first in, first out (FIFO) sequence. The WM_PAINT message, the WM_TIMER message, and the WM_QUIT message, however, are kept in the queue and are forwarded to the window procedure only when the queue contains no other messages. In addition, multiple WM_PAINT messages for the same window are combined into a single WM_PAINT message, consolidating all invalid parts of the client area into a single area. Combining WM_PAINT messages reduces the number of times a window must redraw the contents of its client area.
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
最佳答案
WM_PAINT
和 WM_TIMER
,正如您在文档中阅读的那样,与其他消息不同。
实际的区别是它们是最低优先级的消息。也就是说,如果队列中有任何其他消息,它们将不会被处理。
也就是说,您正在移动鼠标,因此发布了很多消息,但是这些消息的频率通常很低(每秒几十个),因此您的程序应该大部分是空闲的,但事实并非如此,可能是因为其中一些消息花费的时间比预期的要长得多,并且阻塞了队列。你只需要检测哪一个以及为什么。
一些与鼠标相关的消息,我不记得了:
WM_MOUSEMOVE
WM_NCMOUSEMOVE
WM_SETCURSOR
WM_NCHITTEST
WM_MOUSEOVER
WM_MOUSELEAVE
WM_NCMOUSEOVER
WM_NCMOUSELEAVE
WM_PAINT
您应该调用
UpdateWindow()
.此函数强制立即处理
WM_PAINT
(当然,如果有任何无效的东西)并阻塞直到它完成,绕过该消息的低优先级问题。
WM_MOUSEMOVE
将光标位置保存在成员变量中并设置一个标志,表示鼠标已移动。 OnIdle()
检查鼠标移动标志的处理程序。如果不动,什么也不做。如果移动,则进行昂贵的计算。 UpdateWindow()
来自 OnIdle()
看看哪个更好。 OnIdle()
比
WM_TIMER
的优先级更低和
WM_PAINT
,这些消息不会被无限期地降级。更重要的是,您不会对昂贵函数的多次调用进行排队。
关于winapi - 移动鼠标 block WM_TIMER 和 WM_PAINT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22039413/
#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 事件处理程序。 我已经弄清楚如何调用
我是一名优秀的程序员,十分优秀!