Question

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. vs 2010 project on win7

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

rc file of the converted project

but when I build and run the app , the ui look of the buttons is old , unsophisticated. look in the running exe of the converted project

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?

Was it helpful?

Solution

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.

OTHER TIPS

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='*'

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top