What is not valid, update methods in VC ++

I have little doubt about window functions in C ++. what exactly does the "invalidate()" function do? What message does he send when we need to call it? also what is the function "update()" ? "invalidaterect()" works similarly to the function "invalidate()" .

thanks

+6
c ++ visual-c ++ winapi mfc windows-services
source share
2 answers

CWnd::Invalidate() invalidates the entire client area of ​​the window, indicating that the area is outdated and needs to be repainted. Usually you invoke this on a control that needs to be redrawn. CWnd::InvalidateRect() invalidates only part of the window.

Using the Invalidate functions, the WM_PAINT message will be published [not strictly true; see comments] in the message queue and is being processed at some point in the future. CWnd::UpdateWindow() sends (unlike messages) a WM_PAINT message, forcing it to immediately invalidate invalid regions.

Indeed, this is all in the documents.

+6
source share

The invalidate function marks the drawing area as invalid. This flag is used when the window is redrawn; if the region is invalid, it will redraw the region if it does not leave the region of the screen as it is. invalidate invalidates the entire client area of ​​this object; invalidaterect invalidates the specific region of the client area. The update function performs the actual redraw.

The reason for this mechanism, and not just drawing right away when you know something, needs to be changed, is that you can prevent multiple redraws, for example, for example, you received three chat messages at a time that scroll through some text area . If you change the text area for each keystroke, you will have to draw the text area three times, and the application will stop responding. Instead of processing all key events, updating the data structure attached to the text area, and invalidating the text area before you redraw the text field, you redraw the text field only once.

+1
source share

All Articles