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.
本文介绍了Windows编程中创建各种形状区域的方法,如矩形、椭圆形等,并展示了如何使用这些区域进行填充、反转颜色等操作。此外,还讨论了如何将这些区域用作窗口区域以实现非矩形窗口。
484

被折叠的 条评论
为什么被折叠?



