CMFCButton with Vista Style

六月ゝ 毕业季﹏ 提交于 2021-02-04 15:29:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!