15,979
社区成员
发帖
与我相关
我的任务
分享
case WM_NCPAINT:
{
HDC hdc;
hdc = GetDCEx(hwndDlg, (HRGN)wParam, DCX_WINDOW | DCX_INTERSECTRGN);
PAINTSTRUCT ps;
RECT rect;
HBRUSH hbr = CreateSolidBrush(RGB(0, 255, 255));
hbr = (HBRUSH)SelectObject(hdc, hbr);
//填充标题栏颜色
Rectangle(hdc, 0, 0, 40, 200);
ReleaseDC(hwndDlg, hdc);
}
void CMyFileOpenDlg::GradientCaption(CDC* pDC, CRect rRect, COLORREF crFrom, COLORREF crTo )
{
int iHeight = rRect.Height();
int iWidth = rRect.Width();
//
int iR = GetRValue( crFrom );
int iG = GetGValue( crFrom );
int iB = GetBValue( crFrom );
//
int idR = (256*(GetRValue(crTo)-iR)) / iWidth;
int idG = (256*(GetGValue(crTo)-iG)) / iWidth;
int idB = (256*(GetBValue(crTo)-iB)) / iWidth;
iR *= 256;
iG *= 256;
iB *= 256;
// ->
for ( int i = rRect.left; i <= iWidth; i++, iR += idR, iG += idG, iB += idB )
{
pDC->FillSolidRect(i, rRect.top, 1 , iHeight, RGB( iR / 256, iG / 256, iB / 256 ) );
}
}
’
void CMyFileOpenDlg::DrawCaption()
{
// STYLE DS_MODALFRAME |
// WS_CAPTION
// CSize sizeFrame(GetSystemMetrics(SM_CXFRAME),GetSystemMetrics(SM_CYFRAME));
// CSize sizeBorder(GetSystemMetrics(SM_CXBORDER),GetSystemMetrics(SM_CYBORDER));
CSize sizeButton(GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));// 27,27
//
CDC* pWinDC = GetWindowDC();
CRect rcWin;
GetWindowRect(rcWin);
rcWin.OffsetRect(-rcWin.left,-rcWin.top);
// 3 pixel
pWinDC->Draw3dRect(&rcWin,GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_3DSHADOW));
rcWin.DeflateRect(1,1);//
pWinDC->Draw3dRect(&rcWin,GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_3DSHADOW));
rcWin.DeflateRect(1,1);//
pWinDC->Draw3dRect(&rcWin,GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_3DFACE));//COLOR_3DSHADOW));
// back ground
rcWin.DeflateRect(1,1);//
rcWin.bottom=GetSystemMetrics(SM_CYCAPTION)+rcWin.top;
if(m_bActive)
GradientCaption(pWinDC, rcWin, RGB(10,36,106), RGB(164,200,238));
else
GradientCaption(pWinDC, rcWin, RGB(128,128,128), RGB(191,191,191));
// title
pWinDC->SetBkMode(TRANSPARENT);
pWinDC->SetTextColor(RGB(255,255,255));
pWinDC->TextOut(40,6,"SelfDraw Cap",12);
// m_hIcon DrawIcon
LONG style=GetWindowLong(this->m_hWnd,GWL_STYLE);
if(style & WS_SYSMENU) // 0x00080000L
{
DrawIconEx(pWinDC->m_hDC,6,6,m_hIcon,16,16,0,0,DI_IMAGE);
//
CRect rc;
rc.right = rcWin.Width();
rc.left = rc.right - sizeButton.cx+2;
rc.top = rcWin.top+3;
rc.bottom = sizeButton.cy+3;
//
pWinDC->DrawFrameControl(rc,DFC_CAPTION,DFCS_CAPTIONCLOSE);
if((style & WS_MAXIMIZEBOX) || (style & WS_MINIMIZEBOX))
{
rc.OffsetRect(-sizeButton.cx,0);
if(style & WS_MAXIMIZEBOX)
{
if(IsZoomed()) pWinDC->DrawFrameControl(rc,DFC_CAPTION,DFCS_CAPTIONRESTORE);
else pWinDC->DrawFrameControl(rc,DFC_CAPTION,DFCS_CAPTIONMAX);
}
else pWinDC->DrawFrameControl(rc,DFC_CAPTION,DFCS_CAPTIONMAX|DFCS_INACTIVE);
//???
rc.OffsetRect(-sizeButton.cx+2,0);
if (style & WS_MINIMIZEBOX)
pWinDC->DrawFrameControl(rc,DFC_CAPTION,DFCS_CAPTIONMIN);
else
pWinDC->DrawFrameControl(rc,DFC_CAPTION,DFCS_CAPTIONMIN|DFCS_INACTIVE);
}
}
//
ReleaseDC(pWinDC);
}
#if 1
void CMyFileOpenDlg::OnNcPaint()
{
// TODO: Add your message handler code here
DrawCaption();
// Do not call CDialog::OnNcPaint() for painting messages
}
BOOL CMyFileOpenDlg::OnNcActivate(BOOL bActive)
{
// TODO: Add your message handler code here and/or call default
m_bActive=bActive;
// return TRUE;
return CDialog::OnNcActivate(bActive);
}