发出Invalidate()函数后,实际如何运作的呢?是不是就是向消息队列投递一个 WM_PAINT 消息呀?书上这样讲:
Invalidate()的作用是通知窗口的客户区无效,但并不会马上重绘,系统等到下一次 WM_PAINT 消息时,才发生重绘,
可是,这个 WM_PAINT 消息何时才能到来呢?会不会已经通知客户区无效了,但是wm_paint消息就是不到来,如何办呢?我上网找原理的解释,看到有文章说,Invalidate()就是向消息队列投递一个 WM_PAINT 消息。我更糊涂了,到底哪种说法正确呢?

解决方案 »

  1.   

    它会让窗口无效,因为检测到无效窗口,所以系统会产生WM_PAINT消息
      

  2.   

    MSDN上解释:
    The client area is ed for painting when the next WM_PAINT message occurs. The region can also be validated before a WM_PAINT message occurs by the ValidateRect or ValidateRgn member function. The bErase parameter specifies whether the background within the update area is to be erased when the update region is processed. If bErase is TRUE, the background is erased when the BeginPaint member function is called; if bErase is FALSE, the background remains unchanged. If bErase is TRUE for any part of the update region, the background in the entire region, not just in the given part, is erased. Windows sends a WM_PAINT message whenever the CWnd update region is not empty and there are no other messages in the application queue for that window. 
      

  3.   

    注意看最后一句:
    Windows sends a WM_PAINT message whenever the CWnd update region is not empty and there are no other messages in the application queue for that window. 
      

  4.   

    学习了,如果系统要等到别的消息都处理完了再发WM_PAINT,延时的程度会不会足以让程序的显示不正确?
    invalidate之后紧跟一个SendMessage(WM_PAINT)保险一点?
      

  5.   

    如果系统要等到别的消息都处理完了再发WM_PAINT,延时的程度会不会足以让程序的显示不正确?
      

  6.   

    没有这种说法
    不推荐自己发送WM_PAINT消息
      

  7.   

     以下的描述是InvalidateRect的运行机理:
           InvalidateRect 只是将一个区域设置为无效。实际上,Windows为每个窗口维护一个“绘图信息结构”,无效区域的坐标就在其中,每当消息循环空的时候,如果Windows发现存在一个无效区域,就会放入一个WM_PAINT消息。出于效率考虑,WM_PAINT 消息的产生并不意味着整个窗口都需要重新绘制,例如原来有个窗口 B 覆盖了窗口 A 的左上角,则窗口 B 关闭后,窗口 A 就会收到一条 WM_PAINT 消息,但是需要绘制的其实只是左上角的那一部分(为了讨论简单,不考虑窗口自身的内容一直在变化的情况,如动画窗口之类的)。这里的左上角,正是一个“无 效区域”。由此,我们可以解释一下 InvalidateRect 函数了,这个函数的作用非常简单,就是把某个矩形加入到窗口的无效区域列表中,告诉窗口在处理下一条 WM_PAINT 消息时,这个区域是需要重新绘制的。
    如果你想立即更新窗口就得使用UpdateWindow或者RedrawWindow
      

  8.   

    你可以这样做  某函数里 invalidate()之后 updatewindow()  再绘个图    然后再把updatewindow()注释了 看下效果
      

  9.   

    invalidate()
    就是向消息队列中末尾投递一个WM_PAINT消息
    指示无效区域
    如果没有指定理解更新(updatewindow() 函数),
    窗口消息处理函数就会按照顺序从消息队列中挨个取出消息进行处理,你投递的WM_PAINT消息也不知道要等到神马时候,因为要排队嘛
    如果你不想你的WM_PAINT消息排队,那么就直接调用updatewindow() 函数,立即刷新。
      

  10.   


       In    validate()
    // 无     效
    // 所以系统会发送WM_PAINT(窗口消息_刷新)Windows sends a WM_PAINT message whenever the CWnd update region is not empty and there are no other messages in the application queue for that window.
    当然,更行区域不为空,且WM_PAINT之前没有别的消息,才会执行WM_PAINT了
      

  11.   

    Invalidate()无效区重绘