
Change CButton color and CButton text color in CDialog
If you want to use OnCtlColor (which as has already been pointed out,
is exactly the wrong thing for a CButton), you should use a
"reflected" message. Subclass the control whose background you want to
change, make a handler for =WM_CTLCOLOR (note the = in front!), and
you don't need to test for anything because only that control will get
the request. Create the brush in the constructor for the class, and
free it in the destructor of the class.
joe
Quote:
>There are few things to note here.
>According to your subject, you seem want to change CButton color. OnCtlColor
>is not the way to go. You have to owner draw the button. There are several
>examples in button control section at www.codeguru.com.
>In addition, you are leaking brush here. You are creating a new brush each
>time OnCtlColor is called. Eventually you will run out of memory. You should
>create it outside this method (perhaps in OnInitDialog) and simply return
>the brush handle when needed.
Joseph M. Newcomer [MVP]
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm