From: Martijn K. on
Hi everyone!

Got a weird glitch going on while trying to change the text color of a
groupbox.
This is my code:

; Groupbox (button) controls use WM_CTLCOLORSTATIC
; instead of WM_CTLCOLORBTN.

Case WM_CTLCOLORSTATIC

invoke GetDlgCtrlID,lParam

.if eax == IDB_GROUPBOX

invoke SetTextColor,wParam,0000CCFFh ; Random color
invoke GetSysColor,COLOR_MENU
invoke SetBkColor,wParam,eax
invoke GetSysColorBrush,COLOR_MENU ; Return brush handle
ret

.endif

---- or better ----

case WM_CTLCOLORSTATIC:

if(GetDlgCtrlID((HWND) lParam) == IDB_GROUPBOX) {

SetTextColor((HDC)wParam, RG(40, 150,
40)); // Random color
SetBkColor((HDC)wParam, GetSysColor(COLOR_MENU));
return (LRESULT)GetSysColorBrush(COLOR_MENU); // Return
brush handle

}

I know, I could have used a switch instead of the if, but since I want
to change the color for one control only, this seemed the best option.
The problem is this: It works without common controls enabled, but
once I add back the manifest.xml file for the "XP-style" controls, the
SetTextColor and SetBkColor calls don't seem to work, thus only the
background color can be changed by returning a handle to a brush.

I can reproduce this behavior in C/C++ (plain winapi and MFC) also.
After a while of searching, I came to the conclusion SetTextColor and
SetBkColor in combination with common controls just doesn't work. I
can accept this, but could anyone enlighten me as to why it doesn't
work? Why does returning a brush work with and without common
controls? MSDN doesn't give any info about this as far as I see.

Regards,

Martijn
From: Christian ASTOR on
On 6 oct, 06:48, "Martijn K." <tinuskoorem...(a)gmail.com> wrote:
> ................
> I can reproduce this behavior in C/C++ (plain winapi and MFC) also.
> After a while of searching, I came to the conclusion SetTextColor and
> SetBkColor in combination with common controls just doesn't work. I
> can accept this, but could anyone enlighten me as to why it doesn't
> work? Why does returning a brush work with and without common
> controls? MSDN doesn't give any info about this as far as I see.

It's because, when it's themed, the text is drawn with DrawThemeText()
A way to change text color is to draw over with PostMessage()
From: Martijn K. on
On 6 okt, 13:03, Christian ASTOR <casto...(a)club-internet.fr> wrote:
> On 6 oct, 06:48, "Martijn K." <tinuskoorem...(a)gmail.com> wrote:
>
> > ................
> > I can reproduce this behavior in C/C++ (plain winapi and MFC) also.
> > After a while of searching, I came to the conclusion SetTextColor and
> > SetBkColor in combination with common controls just doesn't work. I
> > can accept this, but could anyone enlighten me as to why it doesn't
> > work? Why does returning a brush work with and without common
> > controls? MSDN doesn't give any info about this as far as I see.
>
> It's because, when it's themed, the text is drawn with DrawThemeText()
> A way to change text color is to draw over with PostMessage()

Thanks, that explains a lot. I'll look into the PostMessage() method.
I guess another option would be to subclass the control, but I don't
know if that's worth the extra code.

Regards,

Martijn
(Glad nobody noticed the typo in the RGB macro hehe..)