Dear friends :

I have this problem :

In my app, I put several controls (windows), as
labels, option boxes and group boxes.

I decided to change my window's colors to make it
a little bit more readable.

I changed the colors of my windows, but the can't
change the background color of the controls above.
They are white now.

Did somebody already had this problem?

Any Ideas?

Thanks very much

ssaguiar
Posted on 2001-10-13 18:26:03 by ssaguiar
You should make them transparent. Here is a little piece of C code (sorry, but I don't use ASM):
long CtrlID;


case WM_CTLCOLORSTATIC:

CtrlID = GetWindowLong((HWND)lParam, GWL_ID);

if (CtrlID == IDC_STATIC)
{
SetBkMode((HDC)wParam, TRANSPARENT);
return (long)GetStockObject(NULL_BRUSH);
}

break;

It works for static controls, other types have different messages (WM_CTLCOLORBUTTON, and so on... look at MSDN for a more specific explanation). Maybe give also a look at this old post.
Posted on 2001-10-13 18:54:14 by LuHa
Dear friends :

The problem continues.
Let me explain :

I change the colour of my windows with this, at the beginning of code :


; #########################################################################
; Fill WNDCLASSEX structure with required variables
; #########################################################################

.
.

RGB 168,164,148
mov WinColor,eax
INVOKE CreateSolidBrush, WinColor
mov wc.hbrBackground, eax
.
.

Then, at the creation of my status bar :

invoke SendMessage,hStatus,SB_SETPARTS ,4,ADDR sbParts

invoke SendMessage,hStatus,SB_SETBKCOLOR,NULL,WinColor
.
.
.

Now, for the static controls (radio buttons and label control), and for
my edit control, I paint them returning a brush from :


; #########################################################################

.elseif uMsg == WM_CTLCOLORSTATIC

invoke CreateSolidBrush,WinColor
mov StaticBrush,eax
return eax

; #########################################################################

.elseif uMsg == WM_CTLCOLOREDIT

invoke CreateSolidBrush,WinColor
mov EditBrush,eax
return eax

; ########################################################################


Everything is fine, but, I can't colorize the text's background (the
text of the controls - edit control, label controls and radio button's
labels).

You can see what I means, in the attached picture.

PS :

I tryed also:

; #########################################################################

.elseif uMsg == WM_CTLCOLORSTATIC

invoke GetWindowLong,hWin,GWL_ID

.if eax == IDC_STATIC

invoke SetBkMode,HDC,TRANSPARENT
invoke GetStockObject,NULL_BRUSH
return eax


but it makes my controls grey.

Thanks a lot for any help.


ssaguiar
Posted on 2001-10-19 21:26:09 by ssaguiar
Hi ssaguiar

You must set text background to TRANSPARENT Like this:

.elseif uMsg == WM_CTLCOLOREDIT
invoke SetBkMode,wParam,TRANSPARENT


KetilO
Posted on 2001-10-19 22:28:01 by KetilO
I'm sorry, I gave you some code without explaining it. The

invoke GetWindowLong,hWin,GWL_ID
.if eax == IDC_STATIC

is here only to control wich static control will be painted with a transparent background. It retrieves the sending message control ID and if it is IDC_STATIC next istructions set transparent text background and a null brush. IDC_STATIC is defined (in C) somewhere as:

#define IDC_STATIC 1000

Simply remove that two lines and all static controls will have a transparent background (the null brush returned) and a transparent text background (the SetBkMode).
Posted on 2001-10-20 04:15:25 by LuHa
My Friends :

Thank you very much for your help.
Now it works, but I have to make this way :


; #########################################################################

.elseif uMsg == WM_CTLCOLORSTATIC

invoke SetBkMode,wParam,TRANSPARENT
invoke CreateSolidBrush,WinColor
mov StaticBrush,eax
return eax

; #########################################################################

.elseif uMsg == WM_CTLCOLOREDIT

invoke SetBkMode,wParam,TRANSPARENT
invoke CreateSolidBrush,WinColor
mov EditBrush,eax
return eax

; ########################################################################


If I do not return a brush with my color, then the controls will have a
gray background.

Now all is working fine. Thanks to everybody again.

ssaguiar
Posted on 2001-10-20 12:13:48 by ssaguiar
That works if you have a background painted with a uniform color, but if you have a bitmap you will see colored box around your static text. Did you try returning the NULL_BRUSH instead of your StaticBrush/EditBrush:

invoke GetStockObject, NULL_BRUSH
return eax

instead of:

invoke CreateSolidBrush,WinColor
mov EditBrush,eax ; or mov StaticBrush,eax
return eax

Sorry if I have done some mistakes but I code in C, not asm :grin:.
Posted on 2001-10-20 12:23:43 by LuHa

That works if you have a background painted with a uniform color, but if you have a bitmap you will see colored box around your static text. Did you try returning the NULL_BRUSH instead of your StaticBrush/EditBrush:

invoke GetStockObject, NULL_BRUSH
return eax




Luha,
you have me slightly confused as to what you will achieve by returning a NULL brush. To set the background color of your static/edit boxes to any color, i.e. red/green/yellow/whatever, you return a brush. However, won't returning a NULL brush just paint the background in the system's default color? I'm just querying this in case there is something i have missed... :)
Posted on 2001-10-21 06:42:35 by sluggy
OK, my fault, I meant main window background when I spoke about bitmapped one. Anyway, I will try to explain it in a more precise way. With WM_CTLCOLORxxx you can modify colors used by windows to paint child controls. You can change text color (blue in the picture), text background (red) and control background (black). Text background (the red one) can also be transparent. If the main window has a bitmap as a background you can also use a transparent brush for painting control background.

To set text color blue:
SetTextColor((HDC)wParam, RGB(0, 0, 255));

To set text background transparent:
SetBkMode((HDC)wParam, TRANSPARENT);

To set text background red:
SetBkMode((HDC)wParam, OPAQUE);
SetBkColor((HDC)wParam, RGB(255, 0, 0));

To set control background black (at the end of WM_CTLCOLORxxx handling):
return (long)GetStockObject(BLACK_BRUSH);

To set control background transparent (used with main windows bitmapped backgrounds):
return (long)GetStockObject(NULL_BRUSH);

Again sorry for C code in an ASM board ;).
Posted on 2001-10-21 07:42:35 by LuHa
Sorry boring you all again, people.

Another question, if possible :

How can change the colour of a button, it's text's
colour and the colour of the header of a listview
control and also it's text color?

Thanks again

ssaguiar
Posted on 2001-10-21 18:07:44 by ssaguiar
For button's stuff you should handle WM_CTLCOLORBTN, but I never used it. I think it works like all other WM_CTLCOLORxxx messages. Instead for header controls I'm not sure, but you should use custom drawed ones, painting them by yourself.
Posted on 2001-10-22 11:42:31 by LuHa
Thanks LuHa, great explanation :)
Posted on 2001-10-23 03:01:54 by sluggy