Using the windows API, how can I ensure that controls maintain their own appearance?

Some of the controls that I created default to an old Windows 95 theme, how can I prevent this? Here is an example of a button that does not preserve the appearance of the operating system (I use Vista as a development environment):

HWND button = CreateWindowEx(NULL, L"BUTTON", L"OK", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 170, 340, 80, 25, hwnd, NULL, GetModuleHandle(NULL), NULL); 

I use native C ++ with the Windows API, without managed code.

+4
source share
2 answers

I believe that it has nothing to do with your code, but you need to set up the correct manifest in order to get tethered controls.

Some information here: @ msdn.com and here: @ blogs.msdn.com

Here you can see the difference between the application and without a manifest: heaventools.com

+4
source

To add a manifest to the application, you need to create the MyApp.manifest file and add it to the application resource file:

 //-- This define is normally part of the SDK but define it if this //-- is an older version of the SDK. #ifndef RT_MANIFEST #define RT_MANIFEST 24 #endif //-- Add the MyApp XP Manifest file CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "MyApp.manifest" 

In newer versions of Visual Studio, there is the Manifest Tool tab found in the project settings, and the Additional Manifest Files field found on this tab can also be used to define the manifest file.

Here is a simple MyApp.manifest file for a Win32 application:

 <?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.1" processorArchitecture="X86" name="Microsoft.Windows.MyApp" type="win32" /> <description>MyApp</description> </assembly> 

If the application depends on other DLLs, this data can also be added to the manifest, and Windows will use this information to make sure your application always uses the correct versions of these dependent dlls.

For example, here is the manifest dependency data for shared management libraries and version 8.0 C:

 <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.VC80.CRT" version="8.0.50608.0" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b" /> </dependentAssembly> 
+6
source

Source: https://habr.com/ru/post/1276994/


All Articles