The MASM Forum

General => The Campus => Topic started by: peaslee on September 20, 2015, 03:36:40 AM

Title: Change Button Color
Post by: peaslee on September 20, 2015, 03:36:40 AM
I have been able to change the background of my dialog as well as the static controls, but now the "Close" button sticks out. How do I change the button color to match that of the dialog?
Title: Re: Change Button Color
Post by: Zen on September 20, 2015, 03:48:21 AM
PEASLEE,   
Button (Control Library), MSDN (https://msdn.microsoft.com/en-us/library/windows/desktop/bb775943(v=vs.85).aspx)
WM_CTLCOLORBTN Message (https://msdn.microsoft.com/en-us/library/windows/desktop/bb761849(v=vs.85).aspx)
Title: Re: Change Button Color
Post by: peaslee on September 20, 2015, 06:38:13 AM
Zen,

I found that earlier because a similar message works for static controls. I cannot get WM_CTLCOLORBTN to work. Some folks on the web say it has been eliminated, some that it requires an owner draw button, and some say it never worked.

What I would like would be a simple working example.

Thanks for the response.
Title: Re: Change Button Color
Post by: dedndave on September 20, 2015, 07:38:01 AM
i don't remember ever seeing it work - lol

the button is a tough one - especially on windows 7 or later
the actual button window is a child of a child "worker" window
so, subclassing it is no easy task, either

i've found that, rather than subclassing, write your own button window   :t
Title: Re: Change Button Color
Post by: jj2007 on September 20, 2015, 10:11:39 AM
It's tricky indeed. Here (http://www.programmingforums.org/thread10678.html) they claim that buttons with any *push style can change colours, but I can't confirm that for Win7-64. Besides, notify/NM_CUSTOMDRAW is being proposed.
Title: Re: Change Button Color
Post by: MichaelW on September 21, 2015, 03:41:05 PM
You could try changing the button style to one where you can control the color.

SetWindowLongPtr  (https://msdn.microsoft.com/en-us/library/windows/desktop/ms644898(v=vs.85).aspx)

And if you need to know what the style, or whatever, is GetWindowLongPtr (https://msdn.microsoft.com/en-us/library/windows/desktop/ms633585(v=vs.85).aspx).