InvalidateRect-WINDOWS API

Source: Internet
Author: User

Invalidaterect adds an area to the update area of the specified window. The update area represents a part of the customer area of the window that must be repainted.
Bool invalidaterect (
Hwnd, // handle of the window
Const rect * lprect, // rectangular ELE. Me Coordinate
Bool berase // erased status
);
Parameters:
Hwnd: [enter] A handle window in which the update area has changed. If this parameter is null, the system will invalidate and redraw all windows, and send the wm_erasebkgnd and wm_ncpaint messages to the processing program of the window before the function returns.
Lprect: [input] points to a rect structure that contains the customer coordinates added to the update region. If this parameter is null, the entire customer region is added to the update region.
Berase: [input] indicates whether to erase the background in the update area when the update area is processed. If this parameter is true, the background will be erased when the beginpaint function is called. If the parameter is false, the background will not change.
Return Value:
If the function is successful, the returned value is not 0.
If the function fails, the returned value is 0.
Windows NT/2000/XP: Use getlasterror to get a detailed explanation of the error.
Note:
Invalid regions are accumulated until the next wm_paint message is processed or the region becomes valid through validaterect or validatergn.
The system sends a wm_paint message to a window. No matter whether the update area of the window is empty, there are other messages in the window application queue.
The specified region must have been created using a region function.
If the berase parameter of any part of the updated area is true, the background of the entire area is erased, rather than the specified part.

Required platform:
Windows NT/2000/XP: including after winnt3.1
Win95/98/me: including Versions later than 95
Header file: declared in winuser. H, including windows. h
Library File: user32.lib

Sample Code:
The invalid client region system is not the only source of the wm_paint message. The invalidaterect or invalidatergn function can indirectly generate the wm_paint message for your window, these functions mark all or part of customer zones as invalid (must be repainted ).
In the following example, the window program will invalidate the entire customer zone when processing the wm_char message. This allows the user to input a number to represent and browse the results. Once there are no other messages in the message queue of the application, these results will be drawn.

// Set of points
Point aptpentagon [6] = {50, 2, 98,35, 79,90 },
Apthexagon [7] = {50,2, 93,25, 93,75, 50,98, 7,75, 7,25, 50,2 };
Point * PPT = aptpentagon;
Int CPT = 6; // default vertex book
 
.
.
.
 
Case wm_char:
Switch (wparam)
{
Case '5': // The user entered 5
PPT = aptpentagon;
CPT = 6;
Break;
Case '6': // The user entered 6
PPT = apthexagon;
CPT = 7;
Break;
}
InvalidateRect (hwnd, NULL, TRUE );
Return 0L;
 
Case WM_PAINT:
Hdc = BeginPaint (hwnd, & ps );
GetClientRect (hwnd, & rc );
SetMapMode (hdc, MM_ANISOTROPIC );
SetWindowExtEx (hdc, 100,100, NULL );
SetViewportExtEx (hdc, rc. right, rc. bottom, NULL );
Polyline (hdc, ppt, cpt); // draw a line
EndPaint (hwnd, & ps );
Return 0L;

In this example, the NULL parameter of InvalidateRect indicates the entire customer zone. The TRUE parameter causes the background to be erased. If you do not want the application to wait for no other messages in the message queue of the application to be updated, you can call the UpdateWindow function to force the WM_PAINT message to be sent immediately. If the customer zone has any invalid parts of UpdateWindow, The WM_PAINT message will be sent to the specified window program.

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.