void CSelRectDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CRgn r1, r2, r3; bool combin; CPaintDC dc(this); combin = true; CRect rect1(20, 20, 200, 200); CRect rect2(150, 20, 330, 200); dc.BeginPath(); dc.Ellipse(&rect1); dc.EndPath(); r1.CreateFromPath(&dc); //创建一个圆形路径 dc.Ellipse(&rect1); //画出圆形 dc.BeginPath(); dc.Ellipse(&rect2); dc.EndPath(); r2.CreateFromPath(&dc); dc.Ellipse(&rect2); CString str1; if(r1.CombineRgn(&r1, &r2, RGN_AND) == NULLREGION) //合并重叠区 combin = false; if(combin == true) { CBrush br; br.CreateSolidBrush(RGB(128, 128, 128)); dc.FillRgn(&r1, &br); } CDialog::OnPaint(); } }