CMFCButton with Vista Style

I can not get CMFCButton to appear in Vista style in the dialog box application. I am using VS2008 with the MFC Feature Pack.

Here are some ways to reproduce my problem:

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

test application http://img7.imageshack.us/img7/3/testapp.png

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

What am I missing here?

+4
source share
1 answer

CMFCButton has a BS_OWNERDRAW style by default - you can delete it in OnInitDialog() for your dialog:

 mfcButton.ModifyStyle(BS_OWNERDRAW, 0, 0); 

However, deleting owner-style styles causes many of the CMFCButton methods to be useless (such as SetTextColor). You can get a button for rendering using the current Windows theme by setting up the visual manager:

 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 

This is done instead of ModifyStyle above, as a result, buttons appear that correspond to the default style, but still have newer rendering functions.

+7
source

All Articles