Avatar of Aphroditus
Aphroditus

asked on 

Title bar colour

Is it possible to tweak the title bar's colour and set it by ourselves?
System Programming

Avatar of undefined
Last Comment
mjswart
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
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Aphroditus
Aphroditus

ASKER

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.
Avatar of mjswart
mjswart

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
Avatar of mjswart
mjswart

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 );
}
System Programming
System Programming

Kernel and system programming is the process of creating the software necessary for a computer or device to function and operate other programs. Some operating systems (such as Microsoft Windows) are proprietary, but others, such as the various Linux distributions, are open source.

41K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo