1 CRect rc; 2 Graphics graphics(pDC->m_hDC); 3 GetClientRect(&rc); 4 CRgn m_rgn; 5 6 if (m_pBgImage) 7 { 8 graphics.DrawImage(m_pBgImage, 0, 0, rc.Width(), rc.Height()); //貼背景 9 } 10 if(!m_rgn.m_hObject) 11 { 12 m_rgn.CreateRoundRectRgn((-rc.left) - 1,-rc.top,rc.right - rc.left + 2,rc.bottom - rc.top + 2,15,15); 13 SetWindowRgn(m_rgn,TRUE); 14 }
MFC對話框上貼背景,若是有圓角背景圖片,邊角會作成透明,在生成時背景時,透明處先取底色做爲邊角顏色,以致於在圖片位置改變時或背景改變時本來透明的地方跟其餘地方不和諧,形成毛刺。spa
上面代碼在OnEraseBkgnd(CDC* pDC)裏,讓繪製的圖片去邊角code