CRgn类(区域)
新建对话框类,修改OnPaint(),
void CCRgnDlg::OnPaint() { CPaintDC dc(this); CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP1); BITMAP bm; bmp.GetBitmap(&bm); int cx = bm.bmWidth; int cy = bm.bmHeight; CDC mdc; mdc.CreateCompatibleDC(&dc); mdc.SelectObject(&bmp); /////////////// 创建不规则区域 ///////////////// POINT pts[] = { { 120, 10 }, { 10, 190 }, { 230, 190 }, { 10, 70 }, { 230, 70 }, { 120, 240 }, }; CRgn rg1; rg1.CreatePolygonRgn(pts, 3, WINDING);//创建多边形1 CRgn rg2; rg2.CreatePolygonRgn(pts+3, 3, WINDING);//创建多边形2 rg2.CombineRgn(&rg1, &rg2, RGN_OR);//联合多边形1,2 dc.SelectObject(&rg2); dc.BitBlt(0, 0, cx, cy, &mdc, 0, 0, SRCCOPY); /////////////// 创建圆角矩形区域 ///////////////////// int nLeft = cx - 80; int nTop = cy - 50; CRgn rg3; rg3.CreateRoundRectRgn(nLeft, nTop, nLeft + cx, nTop + cy, 32, 32);//前四个数是Rect的l,t,r,b;最后两个表示圆角的大小 dc.SelectObject(&rg3); dc.BitBlt(nLeft, nTop, cx, cy, &mdc, 0, 0, SRCCOPY); }
在OnPaint函数中添加:
rg2.CombineRgn(&rg2, &rg3, RGN_OR);
SetWindowRgn(rg2, TRUE);
添加WM_NCHITTEST消息映射函数
LRESULT CCRgnDlg::OnNcHitTest(CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 UINT nHitTest = CDialog::OnNcHitTest(point); if (nHitTest == HTCLIENT) nHitTest = HTCAPTION; return nHitTest; }
设置对话框的Border为None,结果如下(可拖动):
原文地址:https://www.cnblogs.com/htj10/p/11780095.html
时间: 2024-10-09 15:23:34