How can I change the color of buttons or edit boxes ? I have already tried to subclass them and handle WM_PAINT, but is doesn't work. Why did this occur and what is the way to do that ?
Thanks
Thanks
For the edit control you respond to WM_CTLCOLOREDIT, for the buttons you must use owner draw, you can get a simple example from my website on owner drawn buttons.
But is it necessary to handle WM_CTLCOLOR messages? I know that there is the possibility of using WM_CTLCOLORBTN to change the color of a button, but I wanna get this stuff through subclassing them, since I have to do that anyway if I want to change the appearance of the buttons on WM_PAINT or WM_SETFOCUS.
:confused: :confused:
:confused: :confused:
Hi,
You will find that WM_CTLCOLORBTN does not work as you might expect, you will have to go the route of owner drawn buttons or you will have no end of troubles. For the edit control, WM_CTLCOLOREDIT is the simplest way to do it, either that or write your own edit control. You can also use a richedit control and set the background color. Doing the edit color in a subclass is difficult to say the least as the text is drawn opaque so it will simply erase any color you use in WM_ERASEBKGND or WM_PAINT. You could superclass the edit then have it subclass it's own parent and process the WM_CTLCOLOREDIT internally, bit of a waste though seeing that the message is easy enough to process. If you want to go the superclassing route you might have a look at this, though I find it unecessarily cumbersome...
You will find that WM_CTLCOLORBTN does not work as you might expect, you will have to go the route of owner drawn buttons or you will have no end of troubles. For the edit control, WM_CTLCOLOREDIT is the simplest way to do it, either that or write your own edit control. You can also use a richedit control and set the background color. Doing the edit color in a subclass is difficult to say the least as the text is drawn opaque so it will simply erase any color you use in WM_ERASEBKGND or WM_PAINT. You could superclass the edit then have it subclass it's own parent and process the WM_CTLCOLOREDIT internally, bit of a waste though seeing that the message is easy enough to process. If you want to go the superclassing route you might have a look at this, though I find it unecessarily cumbersome...