Code:
void CClassname::DrawTitleBar(CDC *pDC)
{
if (m_hWnd)
{
CBrush Brush(RGB(0,100,255));
CBrush* pOldBrush = pDC->SelectObject(&Brush);
CRect rtWnd, rtTitle, rtButtons;
GetWindowRect(&rtWnd);
//Get the position of title
rtTitle.left = GetSystemMetrics(SM_CXFRAME);
rtTitle.top = GetSystemMetrics(SM_CYFRAME);
rtTitle.right = rtWnd.right - rtWnd.left - GetSystemMetrics(SM_CXFRAME);
rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE);
CPoint point;
//draw the top of the frame
point.x = rtWnd.Width();
point.y = GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYFRAME)+20;
pDC->PatBlt(0, 0, point.x, point.y, PATCOPY);
//draw the left of the frame
point.x = GetSystemMetrics(SM_CXFRAME) + 1;
point.y = rtWnd.Height();
pDC->PatBlt(0, 0, point.x, point.y, PATCOPY);
//draw the bottom of the frame
point.x = rtWnd.Width();
point.y = GetSystemMetrics(SM_CYFRAME) + 1;
pDC->PatBlt(0, rtWnd.Height()-point.y, point.x, point.y, PATCOPY);
//draw the right of the frame
point.x = GetSystemMetrics(SM_CXFRAME) + 1;
point.y = rtWnd.Height();
pDC->PatBlt(rtWnd.Width()-point.x, 0, point.x, point.y, PATCOPY);
//Re-draw icon
m_rtIcon.left = rtWnd.Width() - 135;
m_rtIcon.top = GetSystemMetrics(SM_CYFRAME);
m_rtIcon.right = m_rtIcon.left + 32;
m_rtIcon.bottom = m_rtIcon.top + 32;
::DrawIconEx(pDC->m_hDC, m_rtIcon.left, m_rtIcon.top, m_hIcon,
m_rtIcon.Width(), m_rtIcon.Height(), 0, NULL, DI_NORMAL);
m_rtIcon.OffsetRect(rtWnd.TopLeft());
//Prepare for the XP sytle button
CBitmap* pBitmap = new CBitmap;
CBitmap* pOldBitmap;
CDC* pDisplayMemDC=new CDC;
pDisplayMemDC->CreateCompatibleDC(pDC);
//Re-draw close button
rtButtons.left = rtTitle.right - 19;
rtButtons.top = rtTitle.top;
rtButtons.right = rtButtons.left + 19;
rtButtons.bottom = rtButtons.top + 19;
pBitmap->LoadBitmap(IDB_EXIT_NORMAL);
pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
pDisplayMemDC->SelectObject(pOldBitmap);
m_rtButtExit = rtButtons;
m_rtButtExit.OffsetRect(rtWnd.TopLeft());
pBitmap->DeleteObject();
//Re-draw restore button
rtButtons.right = rtButtons.left - 3;
rtButtons.left = rtButtons.right - 19;
if (IsZoomed())
pBitmap->LoadBitmap(IDB_RESTORE_NORMAL);
else
pBitmap->LoadBitmap(IDB_MAX_NORMAL);
pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
pDisplayMemDC->SelectObject(pOldBitmap);
m_rtButtMax = rtButtons;
m_rtButtMax.OffsetRect(rtWnd.TopLeft());
pBitmap->DeleteObject();
//Re-draw minisize button
rtButtons.right = rtButtons.left - 3;
rtButtons.left = rtButtons.right - 19;
pBitmap->LoadBitmap(IDB_MIN_NORMAL);
pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
pDisplayMemDC->SelectObject(pOldBitmap);
m_rtButtMin = rtButtons;
m_rtButtMin.OffsetRect(rtWnd.TopLeft());
pBitmap->DeleteObject();
//Re-draw caption
int nOldMode = pDC->SetBkMode(TRANSPARENT);
COLORREF clOldText=pDC->SetTextColor(RGB(255, 255, 255));
pDC->SelectStockObject(SYSTEM_FIXED_FONT);
rtTitle.left += 2;
rtTitle.top += GetSystemMetrics(SM_CYSIZE);
rtTitle.bottom = rtTitle.top + 30;
CString m_strTitle;
GetWindowText(m_strTitle);
pDC->DrawText(m_strTitle, &rtTitle, DT_LEFT);
pDC->SetBkMode(nOldMode);
pDC->SetTextColor(clOldText);
ReleaseDC(pDisplayMemDC);
delete pDisplayMemDC;
delete pBitmap;
}
}
And you must add a DefWindowProc function and override it
Code:
LRESULT CClassname::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT lrst=CDialog::DefWindowProc(message, wParam, lParam);
if (!::IsWindow(m_hWnd))
return lrst;
if (message == WM_MOVE||message == WM_PAINT||message==WM_NCPAINT||message==WM_NCACTIVATE ||message == WM_NOTIFY)
{
CDC* pWinDC = GetWindowDC();
if (pWinDC)
DrawTitleBar(pWinDC);
ReleaseDC(pWinDC);
}
return lrst;
}