在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)有篇文章講的很到位