问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/1465549/cmfcbutton-with-vista-style