CMFCButton with Vista Style
Asked Answered
P

1

6

I can't seem to get a CMFCButton to be displayed in Vista style in a dialog box application. I'm using VS2008 with MFC Feature Pack.

Here are some steps to reproduce my problem:

  • Create a new MFC Project;
  • Specify a Dialog based project.
  • Add two buttons to the main dialog.
  • Add a variable for each button. Make one of the variables a CButton, the other one a CMFCButton.
  • Compile and run.

test app picture http://img7.imageshack.us/img7/3/testapp.png

As you can see, the CButton has the correct style but the CMFCButton does not.

What I am missing here?

Peril answered 23/9, 2009 at 12:0 Comment(0)
B
9

The CMFCButton has the BS_OWNERDRAW style set by default - you can remove it in the OnInitDialog() for your dialog:

mfcButton.ModifyStyle(BS_OWNERDRAW, 0, 0);

However, removing the owner draw style results in many of the methods of CMFCButton being rendered useless (e.g. SetTextColor). You can get the button to render using the current windows theme by setting up the visual manager:

CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

This is done instead of the ModifyStyle above, resulting in buttons that fit the default style but still have the newer rendering features.

Belomancy answered 23/9, 2009 at 12:12 Comment(2)
Thanks, that solved the problem. But, does this mean I won't have access to CMFCButton specific features, like changing text color?Peril
Good point - turns out there is another way, answer updated with details.Belomancy

© 2022 - 2024 — McMap. All rights reserved.