博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bug: OnIdle called only while mouse's moving
阅读量:7112 次
发布时间:2019-06-28

本文共 1137 字,大约阅读时间需要 3 分钟。

在mfc的group上有这样一个问题:(

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://xyqhl.baihongyu.com/

你可能感兴趣的文章
电力系统【第1章:电力系统概述】
查看>>
web环境搭建
查看>>
Codeigniter出现Unable to connect to your database server using the provided settings错误解决办法...
查看>>
html相对定位绝对定位
查看>>
YII 框架在 MAC OS下 连接数据库失败 提示 DB connection: SQLSTATE[HY000] [2002]
查看>>
poj 2551 Ones
查看>>
HDU 4433 locker
查看>>
PHP----------php-fpm进程数的一些相关配置
查看>>
初始Spring
查看>>
装箱与拆箱
查看>>
设计模式概要
查看>>
053(七)
查看>>
django admin 登陆快速添加验证码功能
查看>>
JS生成二维码
查看>>
免考申请
查看>>
接口和抽象类
查看>>
css 背景透明
查看>>
《深度探索C++对象模型》第一章:关于对象
查看>>
NoSQL 数据库汇总
查看>>
HDU1395 2^x mod n = 1
查看>>