15,979
社区成员
发帖
与我相关
我的任务
分享
void CMyDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if ( cx > 0 && cy > 0 )
{
// Here we calculate the resulting window size from the passed client size
CRect rect( 0, 0, cx, cy );
CalcWindowRect( &rect );
// Here we create the rounded region - you can adjust the 'rounding' using a different 'r'
CRgn rgn;
int r = 50;
rgn.CreateRoundRectRgn( 0, 0, rect.Width(), rect.Height(), r, r );
SetWindowRgn( (HRGN)rgn.Detach(), TRUE );
}
}
void CMyDlg::OnNcPaint()
{
// TODO: Add your message handler code here
// Do not call CDialog::OnNcPaint() for painting messages
const MSG* pMsg = GetCurrentMessage();
CRect rect;
GetWindowRect( &rect );
CRgn rgn;
rgn.CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom );
if ( pMsg->wParam != 1 )
{
// just a part of the window's NC area needs to be drawn, so
// we create a copy of the update region
HRGN hRgn = (HRGN)pMsg->wParam;
rgn.CopyRgn( CRgn::FromHandle( hRgn ) );
// in this case the regions coordinates are screen coordinates,
// so we need to move the region before we fill it
rgn.OffsetRgn( -rect.left, -rect.top );
}
else
{
// the whole window needs to be drawn. In this case we don't need
// to move the region since the window's region is relative to the window
GetWindowRgn( (HRGN)rgn.GetSafeHandle() );
}
CWindowDC dc( this );
CBrush brush;
brush.CreateSolidBrush( RGB( 255, 0, 0 ) );
dc.FillRgn( &rgn, &brush );
}