Development
[VC++] Window 테두리 그리기
알 수 없는 사용자
2010. 7. 6. 17:15
기본적으로 테두리는 WS_THICKFRAME style이 적용 되어 있어야 한다.
void CWnd::OnNcPaint()
{
CRect rcWindow;
GetWindowRect( &rcWindow );
rcWindow.OffsetRect( -rcWindow.left, -rcWindow.top );
int nX = 0;
int nY = 0;
LONG lStyle = ::GetWindowLong( this->GetSafeHwnd(), GWL_STYLE );
// WS_BORDER 속성이 적용되어 있느냐 없느냐에 따라 두께 계산
if ( lStyle & WS_BORDER )
{
nX = GetSystemMetrics(SM_CXSIZEFRAME);
nY = GetSystemMetrics(SM_CYSIZEFRAME);
}
else
{
nX = GetSystemMetrics(SM_CXSIZEFRAME) - GetSystemMetrics(SM_CXBORDER);
nY = GetSystemMetrics(SM_CYSIZEFRAME) - GetSystemMetrics(SM_CYBORDER);
}
CDC* pDC = GetWindowDC( );
// 테두리 영역만을 위해 가운데 영역 제외
pDC->ExcludeClipRect( nX, nY, rcWindow.right - nX, rcWindow.bottom - nY );
{
// 테두리에 그릴 내용
pDC->FillSolidRect( &rcWindow, RGB(255, 0, 0) );
}
ReleaseDC( pDC );
}
{
CRect rcWindow;
GetWindowRect( &rcWindow );
rcWindow.OffsetRect( -rcWindow.left, -rcWindow.top );
int nX = 0;
int nY = 0;
LONG lStyle = ::GetWindowLong( this->GetSafeHwnd(), GWL_STYLE );
// WS_BORDER 속성이 적용되어 있느냐 없느냐에 따라 두께 계산
if ( lStyle & WS_BORDER )
{
nX = GetSystemMetrics(SM_CXSIZEFRAME);
nY = GetSystemMetrics(SM_CYSIZEFRAME);
}
else
{
nX = GetSystemMetrics(SM_CXSIZEFRAME) - GetSystemMetrics(SM_CXBORDER);
nY = GetSystemMetrics(SM_CYSIZEFRAME) - GetSystemMetrics(SM_CYBORDER);
}
CDC* pDC = GetWindowDC( );
// 테두리 영역만을 위해 가운데 영역 제외
pDC->ExcludeClipRect( nX, nY, rcWindow.right - nX, rcWindow.bottom - nY );
{
// 테두리에 그릴 내용
pDC->FillSolidRect( &rcWindow, RGB(255, 0, 0) );
}
ReleaseDC( pDC );
}