1.Create Rgn
Function | Description |
---|---|
CreateRectRgn | Creates a rectangular region from a set of coordinates |
CreateRectRgnIndirect | Creates a rectangular region from a RECT structure or a CRect object |
CreateEllipticRgn | Creates an elliptical region from a set of coordinates |
CreateEllipticRgnIndirect | Creates an elliptical region from a RECT structure or a CRect object |
CreateRoundRectRgn | Creates a rectangular region with rounded corners |
CreatePolygonRgn | Creates a polygonal region from a set of points |
CreatePolyPolygonRgn | Creates a region composed of multiple polygons from a set of points |
CreateFromPath | Creates a region from a path |
CreateFromData | Creates a region by applying two-dimensional coordinate transformations to an existing region |
CopyRgn | Creates a region that is a copy of an existing region |
dc.BeginPath();
TextOut(0,0,_T("Create Font Rng"));
dc.EndPath();
CRgn rgn;
rgn.CreateFromPath(&dc);
2.Combine Rgn
dc.BeginPath();
TextOut(0,0,_T("Create Font Rng"));
dc.EndPath();
CRgn rgn1,rgn2;
CRect rect;
rgn1.CreateFromPath(&dc);
rgn1.GetRgnBox(&rect);
rgn2.CreateRectRgnIndirect(&rect);
rgn1.CombineRgn(&rgn2,&rgn1,RGN_DIFF);
3.Using Region
- CDC::FillRgn fills a region using a specified brush.
- CDC::PaintRgn fills a region using the current brush.
- CDC::InvertRgn inverts the colors in a region.
- CDC::FrameRgn borders a region with a specified brush.
One of the more imaginative uses for a region is to pass it to the CWnd::SetWindowRgn function so that it becomes a window region. A window region is a clipping region for an entire window. Windows doesn't allow anything outside the window region to be painted, including title bars and other nonclient-area window elements. Create an elliptical region and pass its handle to SetWindowRgn, and you'll get an elliptical window. If the window is a top-level window and its title bar is hidden from view, use an OnNcHitTest handler to convert HTCLIENT hit-test codes into HTCAPTION codes so that the window can be dragged by its client area. A more practical use for nonrectangular window regions is to create stylized text bubbles that are actually windows and that receive messages just as other windows do. With SetWindowRgn to assist you, it's not terribly difficult to create a popup window class that displays help text in a window shaped like a thought balloon and that automatically destroys itself when it's clicked.