bug: OnIdle called only while mouse's moving

简介:
在mfc的group上有这样一个问题:( http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.vc.mfc&mid=1aa1eddf-7bcf-407b-84fe-234fe0975331&sloc=en-us
I need to update one  class  data and the view during the idle, I used  this   
method 
in  the Cdoc:
void  CMyAppDoc::OnIdle(){

    theClass
->
Update();
    POSITION pos 
=
 GetFirstViewPosition();
    CView
* pView =
 GetNextView(pos);
    pView
->Invalidate(true
);
    pView
->
UpdateWindow();    
}


It works only when I move the mouse, what
' s wrong? Z_Z
这个问题的确比较搞,要好好看mfc源码的,下面是我的回答
Nothing is wrong, I can explain it  is by design.
Please take a look at the source code of int CWinThread::Run(), in that function, IsIdleMessage() is called, and in IsIdleMessage() WM_PAINT is ignored, which means WM_PAINT will not cause OnIdle to be called, for windows think it's just a WM_PAINT message and will not change the UI.
Your UpdateWindow() only post a WM_PAINT message, the message queue is not empty but it's ignored by IsIdleMessage(), that's why.
But when you move your mouse, the message queue is filled with some WM_MOUSEMOVE and it's not ignored for the position changes. So your OnIdle() is called again.
-
My suggestion is to move your Invalidate & UpdateWindow code to somewhere else.
OnIdle() 的确是个有点复杂的问题,我可能还会写几篇文章 :)
这里( http://groups.google.com/group/microsoft.public.vc.mfc/browse_thread/thread/14f20aa5ffd6994d/66b6e5949a31bfa2?lnk=st&q=AfxUnlockTempMaps&rnum=40&hl=zh-CN#66b6e5949a31bfa2 )有篇文章讲的很到位
目录
相关文章
问题 There is no screen to be resumed matching
问题 There is no screen to be resumed matching
170 0
|
9月前
【Bug】ERROR ResizeObserver loop completed with undelivered notifications.
【Bug】ERROR ResizeObserver loop completed with undelivered notifications.
flag_in_your_hand
flag_in_your_hand
58 0
|
Rust 小程序
小程序警告:Now you can provide attr wxkey for a wxfor to improve performance
首先,无论什么程序,控制台中的警告都是会影响程序性能的。我们需要减少此类警告的出现,以提高程序的运行性能。 小程序开发的时候,遇到了如下的警告:
194 0
LeetCode 322. Coin Change
给定不同面额的硬币 coins 和一个总金额 amount。编写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回 -1。
106 0
LeetCode 322. Coin Change
|
前端开发
Warning: This synthetic event is reused for performance reasons.
Warning: This synthetic event is reused for performance reasons.
535 0
Warning: This synthetic event is reused for performance reasons.
|
程序员
Uncaught ReferenceError: Invalid left-hand side in assignment
Uncaught ReferenceError: Invalid left-hand side in assignment
437 0
|
算法 uml
Draw2d里的Invalidating和Updating
本文部分内容来自Building a Database Schema Diagram Editor with GEF和GEF and Draw2d Plug-in Developer Guide,是对Draw2D里一些基本概念的说明。
1150 0