What factors control dialog button appearance?

不打扰是莪最后的温柔 提交于 2019-12-23 01:43:10

问题


I am a little confused on what are the factors that contribute to the appearance of the UI elements (like buttons) on windows dialogs. My confusion appears out of the following observations:

1- I have visual studio 2010 installed on my system and when I create a MFC dialog , the buttons on the .rc have a sophisticated look , slightly rounded corners etc. when I build the MFC application same appearance comes in the resulting exe.

2- Now I get an application that is developed in VC 6, convert it to new vs 2010 project. When I open the .rc file the UI look is same as described above

but when I build and run the app , the ui look of the buttons is old , unsophisticated.

3- I include InitcommonControlEx() in the old code , and that changes nothing.Perhaps it is not related to this.

My question is what is controlling this look and feel of the ui elements? Is it something to do with the manifest file which directs which version of windows library the application should use?

if so, how can I update the manifest file of the old project , so that I get the new UI look and feel?


回答1:


In VS2010, use the New Project wizard to create an MFC dialog application (actually any MFC application will do). Choose defaults for all options and let the wizard generate the code.

When it's done, look in the file stdafx.h and copy/paste the following block into your stdafx.h

#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

You can also do this via Project/Properties, but by doing it in the code, it won't break if you share the source with other projects.

Note that there is an #ifdef _UNICODE in there because a small number of common controls only work correctly for UNICODE builds. However, if you need and non-UNICODE build and are only using "standard" Windows controls (e.g. no List Views or Tree Views, etc.) it's ok to remove the #ifdef.




回答2:


You are right. You need to embed a manifest file.

The proper way to embed manifest into MFC application with VS2010 is via Properties->Linker->Manifest File->Generate Manifest. To enable XP theme just use the following in the Additional Manifest Dependencies field:

type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'



回答3:


If you would rather not remove the #ifdef _UNICODE statement, you can just copy the line

#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")

and place it at the end of your stdafx.h file. This does EXACTLY the same thing as the the steps recommended by "cha" above, but in fewer steps.



来源:https://stackoverflow.com/questions/15996193/what-factors-control-dialog-button-appearance

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