Link to home
Start Free TrialLog in
Avatar of Aphroditus
Aphroditus

asked on

Title bar colour

Is it possible to tweak the title bar's colour and set it by ourselves?
Avatar of chensu
chensu
Flag of Canada image

Use the SetSysColors function with the following elements.

COLOR_ACTIVECAPTION
COLOR_CAPTIONTEXT
COLOR_GRADIENTACTIVECAPTION
COLOR_GRADIENTINACTIVECAPTION
COLOR_INACTIVECAPTION
COLOR_INACTIVECAPTIONTEXT
Avatar of mjswart
mjswart

It will take more than a tweak.
I assume that you don't want to change the title bar of _all_ windows.

I found this microsoft article on the subject:
HOWTO: Draw a Custom Window Caption
http://support.microsoft.com/support/kb/articles/Q99/0/46.ASP

explanations, sample code etc...

Good luck, Mike
Avatar of Aphroditus

ASKER

I am a real beginner and would like further explanation on how to do this on a dialog box's caption bar instead of the mainframe's...
ASKER CERTIFIED SOLUTION
Avatar of mjswart
mjswart

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mjswart,
may i know which methods of the dialog box must i override...

I don't understand how dialog boxes handle their caption bar. Hope you could shine some light here.
You'll have to add handlers for
WM_NCPAINT and
WM_NCACTIVATE.

Use the class wizard to create OnNcPaint and OnNcActivate for you. Call the default implementations: CDialog::OnNcPaint and CDialog::OnNcActivate and then do your own thing similar to microsoft's page.

Mike
Try to expand on the following:

void CTestingDlg::OnNcPaint()
{
    RECT rc1, rc2;

    // Let Windows do what it usually does. Let the window caption
    // be empty to avoid any Windows-initiated caption bar drawing
    CWnd::OnNcPaint();

    CDC *pDC = GetWindowDC();
    GetWindowRect( (LPRECT)&rc2 );

    // Compute the caption bar's origin. This window has a system box
    // a minimize box, a maximize box, and has a resizeable frame

    int x = GetSystemMetrics( SM_CXSIZE ) +
        GetSystemMetrics( SM_CXBORDER ) +
        GetSystemMetrics( SM_CXFRAME );
    int y = GetSystemMetrics( SM_CYFRAME );
        rc1.left = x;
        rc1.top = y;

    // 2*x gives twice the bitmap+border+frame size. Since there are
    // only two bitmaps, two borders, and one frame at the end of the
    // caption bar, subtract a frame to account for this.

    rc1.right = rc2.right - rc2.left - 2*x -
        GetSystemMetrics( SM_CXFRAME );
    rc1.bottom = GetSystemMetrics( SM_CYSIZE );

    // Render the caption. Use your own color...

    COLORREF cr = pDC->SetBkColor( 0x00777777 );
    pDC->DrawText( (LPSTR)"Left Justified Caption", -1,
        (LPRECT)&rc1, DT_LEFT );
    pDC->SetBkColor( cr );
}