The dialog has a modern look at time design, but an old look at runtime (using Visual C ++ and a resource editor)

I am creating a dialog with the Visual C ++ Resource Editor.
When I launch the test button of the editor, the components of the dialog are displayed with a modern look, and when I start the application that creates and shows the dialog, it is displayed with the old look ... I just use the WINAPI calls to display the dialog, not the MFC. Here is a screenshot (the top image is an example of viewing the user interface at design time, another is viewing the user interface at run time):

link text

Does anyone know what I'm doing wrong?

Thanks in advance,
Henry

+6
windows visual-studio-2008 visual-c ++
source share
6 answers

Does your application manifest indicate that you want to use comctl32.dll version 6? This is one of the requirements for using visual styles and a more modern look in Windows XP.

To create a manifest and enable the app to use visual styles.

Link to ComCtl32.lib and call InitCommonControls (see the documentation for the SDK platform in the MSDN library).

Add a file called YourApp.exe.manifest to the source tree that has the following XML format:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="CompanyName.ProductName.YourApp" type="win32" /> <description>Your application description here.</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly> 

Add the manifest to the application resource file as follows

 CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "YourApp.exe.manifest" 

Note. When you add a previous record to a resource, you must format it on one line. Alternatively, you can put the XML manifest file in the same directory as the application executable. The operating system will first download the manifest from the file system, and then check the resource section of the executable file. The file system version takes precedence.

+4
source share

Do you have a manifest correctly configured to use version 6 of commctl32.dll in your project? If not, you won’t get themed controls.

In later versions of Visual Studio, this is usually done using #pragma, for example (this one for x86 is copied from a new project generated using VS2005):

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

If you add this to one of the source files in your project and rebuild, the manifest will be generated by the linker and added to your application. For other processor architectures, you need to change the value of "architectureArchitecture". (Why VS cannot figure it out on its own remains a mystery to the reader to decide ...)

(As some others noted, you can also manually generate the manifest and add it to the .rc file. This is longer, but gives you full control over the contents of the manifest.)

+4
source share

Some Windows Forms controls will take on a new look as soon as the application is bound to version 6.0 of Comctl32.dll.
and how you can achieve this described in Using Windows XP Visual Styles with Windows Controls
+1
source share

I have a solution for VC6, but I'm not sure if it will work in VS 2008.
(also check this article for what causes the problem)

Here is an example of a simple manifest file that I used to solve it:

Create below XML file,

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="Microsoft.Windows.YourApplication" type="win32" /> <description>YourApplication</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly> 

First add two lines to the resource.h file. Just copy and paste the following:

 #define IDR_MANIFEST 1 #define RT_MANIFEST 24 

Now open the application user resource file. It is usually located in the res directory; The default extension is .rc2. Manually add the following line:

 // Add manually edited resources here... IDR_MANIFEST RT_MANIFEST MOVEABLE PURE "res\\ApplicationManifestXMLFile" 

Replace ApplicationManifestXMLFile with the actual file name (generated by XML).

+1
source share

The question is asked by C ++ and this other question shows how to do this more cleanly.

For .Net 2.0+, please see > this MSDN article < for how to do this with a single line of code, for example:

 Main() { Application.EnableVisualStyles(); } 

I hope this helps someone in finding this topic.

0
source share

Extending existing answers ...

MSDN: Build Requirements for Common Windows Vista Controls

Dropping the following in stdafx.h worked for me and helped to display at runtime the delicate border styling shown in the VS dialog resource editor:

 #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 
0
source share

All Articles