News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SetTextColor vs Common Controls

Started by tinusk, October 05, 2009, 12:49:51 PM

Previous topic - Next topic

tinusk

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    ; COLOR_MENU instead of a NULL-brush (which seems to make the background color white).
        ret

    .endif


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,

tinusk
PS: I know this is more suited towards comp.os.ms-windows.programmer.win32, but I know there are a lot of good win32 programmers on this forum also.  :U

Tedd

SetTextColor and SetBkColor are only meant for changing the properties of line drawing (which includes text and paths.) The background colour refers to the background of drawn text, or fill in shapes - not the background colour of a control.
For changing the control background, you will need to supply it with a brush, in the style of WM_CTLCOLORBTN.
No snowflake in an avalanche feels responsible.