Question

I am using MFC to create a dialog project and trying to impart color to the buttons.

I came to know that the only way you can do is to make the button owner draw. OnCtlColor() does not work for buttons.

I am able to color the button overriding OnDrawItem , but the problem is that , in the process the 3D cool look (with slightly rounded corner that you get in Win7) is lost.

Is there any way to retain the native look and color the button on top of that?

Was it helpful?

Solution

This is not a trivial task. As long as you are using themed controls (what you want), you cannot do more than the theme allows.

You would have to re-implement drawing of the button on your own, making use of the theme API as much as possible to retain themed look, yet sneak-in your color.

Though note that you can hardly achieve anything better than, what .NET WinForms do, when you set the Button.BackColor:

enter image description here

See also question how to set Button BackColor?

Disassembling the WinForms ButtonStandardAdapter.PaintWorker will give you some idea and API you need to use. Beware, you need to do lots of coding!

For C++/MFC code check out Vista themed Owner-Drawn and Full-Custom Push/Menu/Image Buttons on CodeProject. Which probably actually does, what you want already (the SetBackgroundColor method), so you might reuse it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top