37

I have a COM DLL which has a form. This DLL is consumed by a C# application. I have enabled Visual Styles for my C# application. I don't want the Visual Styles be applied for COM DLL's form. But when I run my application and lanuch COM DLL's form, it has visual styles applied to it. How will I prevent it?

Many people suggest using a manifest. But, whatever manifests I see on internet, they all use common controls 6. How to create a manifest that uses common controls 5.0 ? Some also suggest using ActivationContext. But, that too needs correct manifest which uses common controls 5.0 right?

Please suggest something.

Sylca
  • 2,523
  • 4
  • 31
  • 51
Adavesh
  • 557
  • 5
  • 9
  • 10
    You would have to monkey with CreateActCtx in your vb6 code. This is very hard to get right. Having inconsistent styles in your UI makes little sense. – Hans Passant Nov 28 '12 at 15:04
  • 10
    The manifest is per process. You'd need to use an out of process COM host for your window. Note that there are methods for some DLLs to use a different manifest, this requires the host applications support. – Deanna Nov 28 '12 at 15:15
  • 1
    You could try to make the forms from the VB6 DLL work with the common controls 6 manifest. [This VBAccelerator article](http://www.vbaccelerator.com/home/VB/Code/Libraries/XP_Visual_Styles/Using_XP_Visual_Styles_in_VB/article.asp) is a good starting point – MarkJ Nov 28 '12 at 19:56
  • 2
    ... or just turn off visual styles in the C# project, which is likely to be the quickest solution to the problem. I assume you are encountering some problem with the VB6 forms? – MarkJ Nov 29 '12 at 17:41
  • Are you facing the 'black controls' bug with Visual Styles applied to VB6? The workaround for this is to put the 'Black' controls on a pictureBox! – Myrtle Dec 19 '12 at 13:32
  • The reason all of the examples you have found refer to Common Controls v6 is because that is the only version that supports the newer UI. By creating a manifest and referencing v6 you are telling the program to use this newer dll rather then the older v5 version. Perhaps if you used the manifest and specified to use v5 it would work. – Peter Jan 02 '13 at 22:35

1 Answers1

3

If you have a window handle for the form (from the COM DLL) then you can disable visual styles on that form using the Win32 API:

SetWindowTheme( hwnd, "", "" );

I believe you'll have to P/Invoke the API. Here's the definition:

[DllImport("uxtheme.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]
public static extern int SetWindowTheme(
   IntPtr hWnd,
   String pszSubAppName,
   String pszSubIdList);
Peter Ruderman
  • 12,241
  • 1
  • 36
  • 58