love in C++, live on MFC

to get ready...

C++博客 首页 新随笔 联系 聚合 管理
  47 Posts :: 0 Stories :: 97 Comments :: 0 Trackbacks
在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)有篇文章讲的很到位
posted on 2006-07-09 02:03 flyingxu 阅读(1351) 评论(1)  编辑 收藏 引用 所属分类: VC/MFCBug of Today

Feedback

# re: bug: OnIdle called only while mouse's moving 2006-07-09 13:39 LOGOS
关于OnIdle()的事情我也经历过.
我那次将Ogre嵌入了MFC中,引擎的渲染调用放到OnIdle()中激活.
起初无修改的情况下,需要不断移动鼠标才能激活OnIdle()消息(有可能相反,因为我忘记了,不过问题确实存在).
后来所做的修改是在自己实现的OnIdle()中返回TRUE,而不是返回父类OnIdle()的结果,就能连续不断的产生IDLE消息  回复  更多评论
  


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理