Invalidate (TRUE) differs from Invalidate (FALSE) (the former sends a WM_ERASEBKGND message to all refreshes and then draws with the WM_PAINT message, and the latter sends only the WM_PAINT message)

Source: Internet
Author: User
Tags ming

When you use the invalidate (TRUE) function, it adds the WM_ERASEBKGND and WM_PAINT two messages to the message queue.

When you use the invalidate (FALSE) function, it only adds a WM_PAINT message to the message queue.

The role of the WM_ERASEBKGND message fills the client area with a background color, so he will draw the image before the situation, and then respond to the WM_PAINT message, calling the OnPaint function to respond to the image drawing work. So invalidate (TRUE) is the equivalent of emptying the original painting and redrawing it.

When invalidate (TRUE) sends only WM_PAINT messages, the OnPaint function is called to respond to the image drawing work. Therefore, the function of invalidate (TRUE) is equivalent to continue drawing on the basis of the original drawings.

For example: Xiao Ming is going to draw on the blackboard, he is going to draw a chicken and a duck.

Situation one: When the chicken was painted, Xiao Ming felt that the painting is not like, so the blackboard wiped off the painted chicken, re-painting. This is relative to the processing of the invalidate (TRUE) function.

Scenario Two: When the chicken, Xiao Ming thought the painting to be realistic, so on this basis continue to draw another duck. This is relative to the invalidate (FALSE) process.

Experiment Source (Dialog project, add code in OnPaint function):

[CPP]View PlainCopy  
    1. CPaintDC DC (this);
    2. int x = rand ()%200;
    3. int y = rand ()% 200;
    4. dc. Ellipse (CRect (CPoint (x, y), CSize (100, 100));
    5. x = rand ()% 200;
    6. y = rand ()% 200;
    7. CBrush Brush (RGB (0, 0, 255));
    8. dc. FillRect (CRect (CPoint (x, y), CSize (), &brush);

Set the timer in the OnInitDialog function:

SetTimer (1, +, NULL);

Add the Wm_time message response and add it in the OnTimer function:

Invalidate (TRUE);

Operation Result:

Instead, change invalidate (TRUE) to:

Invalidate (FALSE);

The result of the operation is:

Visible: Invalidate (FALSE) does not empty the previously drawn image.

If you want to use Invalidate (TRUE) to achieve the same effect as invalidate (FALSE), you can add a function to the WM_ERASEBKGND message response, and modify the ONERASEBKGND function to:

[CPP]View PlainCopy 
    1. BOOL caadlg::onerasebkgnd (cdc* PDC)
    2. {
    3. return TRUE;
    4. }

The effect of invalidate (TRUE) at this time is the same as invalidate (FALSE).

Original: http://m.blog.csdn.net/blog/piaopiaopiaopiaopiao/41521211

http://blog.csdn.net/chence19871/article/details/49929171

Invalidate (TRUE) differs from Invalidate (FALSE) (the former sends a WM_ERASEBKGND message to all refreshes and then draws with the WM_PAINT message, and the latter sends only the WM_PAINT message)

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.