Differences between invalidate and updatewindow

Source: Internet
Author: User
  1. Invalidate adds a wm_paint message to the message queue, and its invalid zone is the entire customer zone.
  2. Updatewindow directly sends a wm_paint message. Its invalid zone range is the invalid zone of the wm_paint message in the Message Queue (up to one.
  3. The effect is obvious. After invalidate is called, the screen may not be updated immediately, because the wm_paint message is not necessarily in the queue header, and calling updatewindow will immediately execute the wm_paint message, bypassing the message queue.
  4. If you want to update the screen immediately after invalidate is called, add the updatewindow () statement.

Msdn explanation
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.

A rough explanation of the Translation into Chinese is as follows:
Updatewindow:If there is no effect zone, sending a wm_paint message will be sent to the window for processing immediately. If the message queue is not entered for waiting, refresh the window immediately. Otherwise, nothing will be done.
Invalidaterect: Set the invalid partition. If the parameter is null, set the entire window to an invalid partition. When the message queue of the window of the application is empty, sending a wm_paint message (even if the update area is empty) is accumulated in all invalidaterect update areas of sending a wm_paint message.

1: Set invalid Zone
Invalidaterect

2: refresh now
Updatewindow ();

If you call updatewindow without calling invalidaterect, then updatewindow does not do anything.??????
If you do not call updatewindow after invalidaterect is called, the system automatically sends a wm_paint message when the window message queue is empty.

When updatewindow () is called, a wm_paint message is sent, and the application automatically calls invalidate () After receiving the wm_paint message (),Therefore, invalidate () does not have to appear in the program code ()!

Updatewindow () is to send the wm_paint message immediately. It only takes effect for the declared invalid region,
Invalidate () is one of the methods in which the statement is invalid.

Invalidate () indicates that the customer region is invalid., Re-paint the next time wm_paint occurs.Wm_paint is maintained by the system. When the update area of cwnd is not empty and there are no other messages in the window message queue of the application, Windows sends a wm_paint message..
Invalidate contains a bool parameter to identify whether to fill the background color during repainting. Is the setbkcolor function used? Continue to study.

Updatewindow requires the system to re-paint the area immediately.

Someone asked a question online. He wrote the drawing function after invalidate but didn't execute it because invalidate was executed and then transferred to the paint command. So none of them are displayed.

I finally figured out that the image I painted was always flashing, because I used the invalidate () function in the painting, so he kept self-nesting, but the painted image kept flashing.

 

Invalidate puts the customer area in the redraw state, while updatewindow starts to redraw. However, it first checks whether the customer area is empty. If it is not empty, updatewindow does not execute. If it is empty, re-draw is performed.

 

Invalidat is finally called invalidatrectIn Windows API, only

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.