Visual styles don't work on an in-process COM server

6

I am developing a program which uses visual styles. The Main method looks like this:

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

The program also works as a plugin of another application and it is started, in this case, via COM. The problem is that the calling application (the COM client) doesn't call EnableVisualStyles and it is out of my control. In this case the program is started as follows:

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

When the program is started as a plugin the progress bars and the combo boxes are not rendered with the same style they have when the program is started normally, while buttons, check boxes and radio buttons are OK. Is there a way to force the visual style? I've tried with a manifest but with no luck! Here is the manifest that 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 that the manifest is embedded correctly because ildasm shows the following in the manifest section:

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

Thanks, Stenio

c#
.net
winforms
plugins
com
asked on Stack Overflow Nov 28, 2011 by stenio • edited Nov 28, 2011 by stenio

1 Answer

2

In the words of Raymond Chen, a plugin is a guest in the host process, and shouldn't be changing the carpets.

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

There is no way to turn them on because it is not really something you should be doing.

If the host process does not want to use visual styles you probably shouldn't be using them. Consider allowing your plugin to render without visual styles when hosted in an application without visual styles.

Otherwise, see @Ken's advice above.

answered on Stack Overflow Dec 29, 2011 by Ben

User contributions licensed under CC BY-SA 3.0