The following three plot functions need a pointer to the rectangular structure:
Fillrect (HDC, & rect, hbursh); // fill
Framerect (HDC, & rect, hbrush); // empty
Invertrect (HDC, & rect); // internal Inversion
Case wm_paint: HDC = beginpaint (hwnd, & PS); // getclientrect (hwnd, & rect); // hrgn = createrectrgn (100,100,300,300 ); // hbrush = createsolidbrush (RGB (255, 0, 0); // fillrgn (HDC, hrgn, hbrush); // invertrgn (HDC, hrgn ); // obtain the reverse result // framergn (HDC, hrgn, hbrush, 100); r1.left = 100; r1.top = 200; r1.right = 200; r1.bottom =; hbrush = createsolidbrush (RGB (200, 0, 0); // create an image brush fillrect (HDC, & R1, hbrush); r2.left = 100; r2.top = 300; r2.right =; r2.bottom = 200; framerect (HDC, & R2, hbrush); r3.left = 300; r3.top = 100; r3.right = 400; r3.bottom = 200; invertrect (HDC, & R3 ); endpaint (hwnd, & PS); Return 0;
There are also eight operations on rectangles:
Offsetrect (& rect, x, y) |
Move the rectangle |
Inflaterect (& rect, x, y) |
Increase or decrease the size of the rectangle |
Setrectempty (& rect) |
Set the fields of the rectangle structure to 0. |
Copyrect (& destrect, & scrrect) |
Copy a rectangle structure to another rectangle Structure |
Intersectrect (& destrect, & srcrect1, & srcrect2) |
Returns the intersection of two rectangles. |
Unionrect (& destrect, & srcrect1, & srcrect2) |
Obtains the union of two rectangles. |
Bempty = isrectempty (& rect) |
Determines whether the rectangle is empty. |
Binrect = ptinrect (& rect, point) |
Determines whether the vertex is inside the rectangle. |
The area is the same as the rectangle and has the following four plot functions.
FillRgn(hdc,hrgn,hbrush);FrameRgn(hdc,hbrush,xFrame,yFrame);InvertRgn(hdc,hrgn);PaintRgn(hdc,hrgn);
DeleteObject(hrgn);
SelectObject(hdc,hrgn)=SelectClipRgn(hdc,hrgn);
Functions that make the rectangle and region valid and invalid
InvalidateRect ValidateRectInvalidateRgn ValidateRgn
The following is a simple example:
Case wm_paint: HDC = beginpaint (hwnd, & PS); // getclientrect (hwnd, & rect); // hrgn = createrectrgn (100,100,300,300 ); // hbrush = createsolidbrush (RGB (255, 0, 0); // fillrgn (HDC, hrgn, hbrush); // invertrgn (HDC, hrgn ); // obtain the reverse result // framergn (HDC, hrgn, hbrush, 100); r1.left = 100; r1.top = 200; r1.right = 200; r1.bottom =; hbrush = createsolidbrush (RGB (150, 0, 0); // create a paint brush // fillrect (HDC, & R1, hbrush); r2.left = 100; r2.top = 250; r2.right =; r2.bottom = 200; // framerect (HDC, & R2, hbrush); intersectrect (& R3, & R1, & R2); // R1, R2 take the intersection of rectangles, stored in r3fillrect (HDC, & R3, hbrush); flag = (INT) isrectempty (& R3); // determines whether the rectangle is null textout (HDC, 300,300, szbuffer, wsprintf (szbuffer, text ("% d"), flag); endpaint (hwnd, & PS); Return 0;
hrgn=CreateRectRgn(xleft,ytop,xright,ybottom);hrgn=CreateRectRgnIndirect(&rect);hrgn=CreateEllipticRgn(xleft,ytop,xright,ybottom);hrgn=CreatePolygonRgn(&point,icount,ipolyFillMode);