我看有些代码中在invalidaterect执行后,还紧跟着updatewindow?
invalidaterect执行后,不是会发送一个wm_paint消息吗?为何后面还要用updatewindow再发送一个wm_paint消息?不明白,还请各位大侠指点,谢谢!

解决方案 »

  1.   


    InvalidateRect并不向指定窗口发消息, 只是通知系统有区域需要更新, 但系统不会立即发送WM_PAINT, 除非消息队列已空.UpdateWindow则是直接向目的窗口发送WM_PAINT消息, 但前提是需要有invalidate的区域.
      

  2.   

    invalidaterect()后,系统不会立即发送wm_paint消息。要等到消息处理完后再发送wm_paint消息
    updatewindow强制立即发送wm_paint消息msdn对invalidaterect解释:
    The system sends a WM_PAINT message to a window whenever its update region is not empty and there are no other messages in the application queue for that window. 
      

  3.   

    如果有无效区,则马上sending a WM_PAINT message到窗口处理过程,不进消息队列进行排队等待,立即刷新窗口,否则,什么都不做。InvalidateRect:设置无效区,如果为NULL参数,则设置整个窗口为无效区。当应用程序的那个窗口的消息队列为空时,则sending a WM_PAINT message(即使更新区域为空).在sending a WM_PAINTmessage的所有InvalidateRect的更新区域会累加。
    1:设置无效区 <br>InvalidateRect 
    2:立即刷新 UpdateWindow()
    如果不调用InvalidateRect就调用UpdateWindow,那么UpdateWindow什么都不做。如果调用InvalidateRect后不调用UpdateWindow,则系统会自动在窗口消息队列为空的时候,系统自动发送一WM_PAINT消息