Visual styles do not work on COM server in process

I am developing a program that uses visual styles. The main method is as follows:

[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form()); } 

The program also works as a plug-in of another application and is launched in this case through COM. The problem is that the calling application (COM client) does not call EnableVisualStyles, and it is not at my disposal. In this case, the program starts as follows:

 public static void StartAsPlugin() { Application.EnableVisualStyles(); Form form = new Form(); form.ShowDialog(); } 

When the program starts as a plugin, progress indicators and combined fields are not displayed in the same style as during normal program operation, while the buttons, check boxes and radio buttons are in order. Is there a way to force a visual style? I tried with the manifest, but no luck! Here is the manifest I tried:

 <?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="*" name="RealApp" type="win32" /> <description>Your application description here.</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly> 

I think the manifest is built in correctly because ildasm shows the following in the manifest section:

 .mresource public RealApp.RealApp.exe.manifest { // Offset: 0x000004F0 Length: 0x0000029B } 

Thanks Stenio

+6
source share
1 answer

According to Raymond Chen, the plugin is a guest in the host process and should not change carpets.

http://blogs.msdn.com/b/oldnewthing/archive/2010/04/30/10004931.aspx

It is impossible to turn them on, because that is not what you should do.

If the host process does not want to use visual styles, you probably shouldn't use them. Think about how your plugin can render without visual styles when placed in an application without visual styles.

Otherwise, see @Ken's recommendation above.

+2
source

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


All Articles