The study of Programming Windows with MFC--CRgn

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.Create Rgn

  

FunctionDescription
CreateRectRgnCreates a rectangular region from a set of coordinates
CreateRectRgnIndirectCreates a rectangular region from a RECT structure or a CRect object
CreateEllipticRgnCreates an elliptical region from a set of coordinates
CreateEllipticRgnIndirectCreates an elliptical region from a RECT structure or a CRect object
CreateRoundRectRgnCreates a rectangular region with rounded corners
CreatePolygonRgnCreates a polygonal region from a set of points
CreatePolyPolygonRgnCreates a region composed of multiple polygons from a set of points
CreateFromPathCreates a region from a path
CreateFromDataCreates a region by applying two-dimensional coordinate transformations to an existing region
CopyRgnCreates 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.

     

     

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风水月

从心底相信自己是成功的第一步

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值