UpdateWindow和Invalidate的區別

來源:互聯網
上載者:User

UpdateWindow和Invalidate的區別

 

MSDN的解釋
UpdateWindow
The   UpdateWindow   function   updates   the   client   area   of   the   specified   window   by   sending   a   WM_PAINT   message   to   the   window   if   the   window 's   update   region   is   not   empty.   The   function   sends   a   WM_PAINT   message   directly   to   the   window   procedure   of   the   specified   window,   bypassing   the   application   queue.   If   the   update   region   is   empty,   no   message   is   sent.  

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.  

翻譯成中文大概的解釋如下:
    UpdateWindow:如果有無效區,則馬上sending   a   WM_PAINT   message到視窗處理過程,不進訊息佇列進行排隊等待,立即重新整理視窗,否則,什麼都不做。
  InvalidateRect:設定無效區,如果為NULL參數,則設定整個視窗為無效區。當應用程式的那個視窗的訊息佇列為空白時,則sending   a   WM_PAINT   message(即使更新地區為空白).在sending   a   WM_PAINT   message的所有InvalidateRect的更新地區會累加。

 

所以一般的用法是

  1:設定無效區
  InvalidateRect

  2:立即重新整理
  UpdateWindow();

如果不調用   InvalidateRect就調用   UpdateWindow,那麼UpdateWindow什麼都不做。
如果調用   InvalidateRect   後不調用UpdateWindow,則系統會自動在視窗訊息佇列為空白的時候,系統自動發送一WM_PAINT訊息。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.