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
- CPaintDC DC (this);
- int x = rand ()%200;
- int y = rand ()% 200;
- dc. Ellipse (CRect (CPoint (x, y), CSize (100, 100));
- x = rand ()% 200;
- y = rand ()% 200;
- CBrush Brush (RGB (0, 0, 255));
- 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
- BOOL caadlg::onerasebkgnd (cdc* PDC)
- {
- return TRUE;
- }
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)