INTRODUCTION AND RELEVANT INFORMATION:
I have 2
dialog boxes created via
Resource Editor. Since I use
Microsoft Visual Studio Express edition, I had to download
free resource editor[
^]. In my program, I have visual styles enabled like this:
#include <commctrl.h>
#pragma comment( lib, "comctl32.lib")
#pragma comment( linker, "/manifestdependency:\"type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
language='*'\"")
As far as I know,
check box,
radio button, and
group box get
WM_CTLCOLORSTATIC
message for painting their text. This is what I have coded for the first
dialog box:
case WM_CTLCOLORSTATIC:
{
SetBkMode( (HDC)wParam, TRANSPARENT );
SetTextColor( (HDC)wParam, RGB( 0, 0, 0 ) );
return (INT_PTR)( (HBRUSH)GetStockObject(NULL_BRUSH) );
}
I just want those controls to have transparent text background and black color of their text.
THE PROBLEM:
On Windows XP[
^], the result for first dialog is that
check box and it's text are painted properly, but the text background is black.
Group box has brown borders, text background has proper transparent color, but text is blue. Radio button is painted properly.
On Windows 7[
^], after starting the same program,
group box and
check box have proper text color, yet text background of the
check box and the border of the group box are wrong - they are both white.
Radio button has proper text color, but text background is gray.
In my
dialog box, I have
static controls and they are painted properly
both on
Windows 7 and
Windows XP.
MY EFFORTS TO SOLVE THE PROBLEM:
I have browsed through
StackOverflow archive, and tried searching here at
CodeProject, but haven't found anything I could use to modify my
WM_CTLCOLORSTATIC
handler.
I have found an example which
removes Visual Styles
from those controls, so it can achieve the desired result, but I need to keep the
Visual Styles
and make the background of the text transparent, thus this solution can not satisfy me.
After looking through
Visual Styles
reference and a little experimenting, I have found a workaround for
radio button and
check box ( but not for
group box ) with the following code:
case WM_CTLCOLORSTATIC:
if( (HWND)lParam == GetDlgItem( hwnd, IDC_RADIO1 ) )
{
RECT r;
GetClientRect( hwnd, &r );
DrawThemeParentBackground( (HWND)lParam, (HDC)wParam, &r );
}
else
{
SetTextColor( (HDC)wParam, RGB( 0, 0, 0 ) );
SetBkMode( (HDC)wParam, TRANSPARENT );
}
return (INT_PTR)( (HBRUSH)GetStockObject(NULL_BRUSH) );
Still, I have "hit the wall" with this:
In my
dialog box there is a
treeview and once I select node and press
spacebar ( or any other key for that matter )
dialog's background bitmap gets on top of my
static controls.
After I comment out DrawThemeParentBackground()
, recompile and start program again everything works fine ( when I select tree's node and press
spacebar ) but then I am "at square one".
THE QUESTION:
1. How can I modify my
WM_CTLCOLORSTATIC
handler to fix my problem ?
2. If the above is not possible, can I get the desired effect with
NM_CUSTOMDRAW
?
NOTE:
I think that I will have to draw
group box using
GDI
. If that is the case, I will accept this solution too, as my main concern is
checkbox and
radio button.
Thank you.
Best regards.