Aphroditus
asked on
Title bar colour
Is it possible to tweak the title bar's colour and set it by ourselves?
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
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 );
}
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 );
}
COLOR_ACTIVECAPTION
COLOR_CAPTIONTEXT
COLOR_GRADIENTACTIVECAPTIO
COLOR_GRADIENTINACTIVECAPT
COLOR_INACTIVECAPTION
COLOR_INACTIVECAPTIONTEXT