How to draw static controls and check box buttons transparently ?
-
I'd like to have my tabbed dialog application using XP themes like "My Computer-> properties" in the win XP - the dialog inside the TAB control should use gradient background. My problem is that static controls and check box buttons are not drawn properly -> background of the text is erased by default dialog background color (text background has OPAQUE mode). I've tried to handle the WM_CTLCOLOR message in the dialog, but this solved only the problem with text static controls, not with the group rectangle static box (it's text was drawn over the rectangle line when I've set text background mode to TRANSPARENT). I hope there is some easier way than to code my own owner drawn controls, when windows GUI is using this. Any suggestions ? Thanks !
rrrado
-
I'd like to have my tabbed dialog application using XP themes like "My Computer-> properties" in the win XP - the dialog inside the TAB control should use gradient background. My problem is that static controls and check box buttons are not drawn properly -> background of the text is erased by default dialog background color (text background has OPAQUE mode). I've tried to handle the WM_CTLCOLOR message in the dialog, but this solved only the problem with text static controls, not with the group rectangle static box (it's text was drawn over the rectangle line when I've set text background mode to TRANSPARENT). I hope there is some easier way than to code my own owner drawn controls, when windows GUI is using this. Any suggestions ? Thanks !
rrrado
Looks strange because when an XP theme is active, all text labels are drawn transparently; in fact, no WM_CTLCOLOR handling is necessary. Does your app have a manifest resource in it that enables theming (the XP look) when a theme is active? The gradient that you see in "My Computer-> properties" is NOT a feature of a themed Tab control, it's how the theme handles property sheets - it applies a gradient background to each of the dialog in the sheet. If you create your own tabbed dialog, you can do it by handling WM_ERASEBKGND in each of your dialogs. Consider the following code excerpt; perhaps you will get some ideas on your group boxes (BTW, they belong to window class BUTTON, not STATIC):
BOOL myGroupBox::OnEraseBkgnd(CDC* pDC)
{
CRect rcCtrl;
GetClientRect(rcCtrl);if (GetUXThemeState().IsThemeActive()) pDC->FillSolidRect(rcCtrl, ColorAdjustLuma(afxData.clrBtnFace, 750, TRUE)); else pDC->FillSolidRect(rcCtrl, afxData.clrBtnFace); PrintClient(pDC, PRF\_CLIENT); return 1;
}
void myGroupBox::OnPaint()
{
// validates the invalid area to prevent the infinite paint loop
PAINTSTRUCT ps = {0};
::BeginPaint(m_hWnd, &ps);
::EndPaint(m_hWnd, &ps);
}One always gets the deserved.
http://www.silveragesoftware.com/hffr.html
Update your source code with my tool HandyFile Find And Replace! -
Looks strange because when an XP theme is active, all text labels are drawn transparently; in fact, no WM_CTLCOLOR handling is necessary. Does your app have a manifest resource in it that enables theming (the XP look) when a theme is active? The gradient that you see in "My Computer-> properties" is NOT a feature of a themed Tab control, it's how the theme handles property sheets - it applies a gradient background to each of the dialog in the sheet. If you create your own tabbed dialog, you can do it by handling WM_ERASEBKGND in each of your dialogs. Consider the following code excerpt; perhaps you will get some ideas on your group boxes (BTW, they belong to window class BUTTON, not STATIC):
BOOL myGroupBox::OnEraseBkgnd(CDC* pDC)
{
CRect rcCtrl;
GetClientRect(rcCtrl);if (GetUXThemeState().IsThemeActive()) pDC->FillSolidRect(rcCtrl, ColorAdjustLuma(afxData.clrBtnFace, 750, TRUE)); else pDC->FillSolidRect(rcCtrl, afxData.clrBtnFace); PrintClient(pDC, PRF\_CLIENT); return 1;
}
void myGroupBox::OnPaint()
{
// validates the invalid area to prevent the infinite paint loop
PAINTSTRUCT ps = {0};
::BeginPaint(m_hWnd, &ps);
::EndPaint(m_hWnd, &ps);
}One always gets the deserved.
http://www.silveragesoftware.com/hffr.html
Update your source code with my tool HandyFile Find And Replace!Thank you very much for your response. I'll try your code. I don't use property sheets besause of it's limitations. I have tab control which has child dialogs. I'm handling the child dialog's onEraseBackgroud where I do nothing, so oridinal tab control's background remains. I have manifest file in my resources, so all buttons, group boxes, etc. looks like in Win XP theme. So I don't know why my static controls are not drawn transparently by default :confused: I'm also calling InitCommonControls(); in the app's InitInstance() as recommended ...
rrrado
-
Thank you very much for your response. I'll try your code. I don't use property sheets besause of it's limitations. I have tab control which has child dialogs. I'm handling the child dialog's onEraseBackgroud where I do nothing, so oridinal tab control's background remains. I have manifest file in my resources, so all buttons, group boxes, etc. looks like in Win XP theme. So I don't know why my static controls are not drawn transparently by default :confused: I'm also calling InitCommonControls(); in the app's InitInstance() as recommended ...
rrrado
Could you make a small screenshot of the text label portion of a group box and give a link? this can make the native Windows drawing procedure more clear. Oh... I think all you have to do is give your group boxes sensible ID's (other than
-1
/IDC_STATIC
/), check them in theWM_CTLCOLOR
handler, callpdc->SetBkColor()
for these ID's and return a brush of a proper color. Do not set the background mode toTRANSPARENT
. One always gets the deserved.
http://www.silveragesoftware.com/hffr.html
Update your source code with my tool HandyFile Find And Replace!