News:

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

Change Dialog Item Text Colour

Started by colinr, March 17, 2012, 05:31:06 PM

Previous topic - Next topic

colinr

Hi All,

I'm trying without success to change the text colour from black to red on certain buttons within a dialog.

I have designed the Dialog using an editor and I am displaying it using the DialogBoxParam function.

All the examples that I have seen seem to generate the DialogBox using the CreateWindowX function which is way beyond by knowledge!!

I understand that it uses WM_PAINT but I have no idea how to use this within my code.

Thanks in advance, Colin.

dedndave

you can create a hook for the buttons to change color
i used a CBT hook
let me see if i can find some working code...

well - i have done it before - lol
can't find the code, now

dedndave

as i recall, it went something like this...
use a CBT hook to sub-class the button
after that, i seem to recall WM_CTLCOLORSTATIC will change the color

WM_CTLCOLORSTATIC:
invoke SetTextColor....
mov eax,hBrush
ret

colinr

I wish that I knew what you were talking about  :(

It is simple enough to change the actual text from within a button, however, changing the text colour is another thing! - I've looked at loads of examples and never once managed to get it to work!

Thanks, Colin.

dedndave

sorry Colin - i didn't have time to play with it, yesterday
today, i will see if i can make an example
one of the other guys will probably beat me to it - lol

this code is wrong  :'(
WM_CTLCOLORSTATIC:
invoke SetTextColor....
mov eax,hBrush
ret

you return the background brush handle for WM_CTLCOLORSTATIC - not the forground

donkey

If you just want to change the text color in a button you should be using owner draw buttons, they're pretty simple to use. I put together this example in about 10 minutes, you store the text color in GWL_USERDATA, only single line buttons are supported for the example and it handles disabled buttons. (GoAsm syntax ofcourse and you need my headers to build it, executable is included)

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dedndave

yes - but you don't get the nice UxTheme gradient button   :P

donkey

Quote from: dedndave on March 18, 2012, 01:57:30 PM
yes - but you don't get the nice UxTheme gradient button   :P

Ah well, can't have everything I suppose, though you can draw pretty much anything you want to the DC while you own it so you can always use the DrawThemeXXXX functions instead.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dedndave

i have done it with MessageBox, before - it wasn't that bad
although, changing the color of the message text requires completely different code than the button   :P

dedndave

i haven't forgotten you, Colin
still playing with code   :P

dedndave

ok - i give up - lol
i thought i had done this before - maybe it was with a custom MessageBox, which is a bit different
other than subclassing the button and wriiting your own paint routine, i can't see how to do it with a non-owner-drawn button
it is easy to do for a static text control   :P

colinr

OK, thanks for all your efforts anyway  :bg

I'm just having a look at Windows XP calculator, see if I can work out how MS have done it!

Just out of interest what does hDC have to equal?

dedndave

hDC is a handle to the "device context"
normally, it comes from the PAINTSTRUCT after BeginPaint, in response to receiving a WM_PAINT message
(BeginPaint also returns the hDC in EAX)

a lot of good reading...
http://msdn.microsoft.com/en-us/library/dd183315%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/dd162467%28v=VS.85%29.aspx