1

I have an addin for Office 2007 which adds a toolbar with some buttons and handlers for their OnClick events. When the user clicks on the buttons, some dialogs show. But those dialogs have the dated Windows 98 look and feel with rectangular buttons, even on Windows 7.

I know that you need a manifest file to enable theming, but this addin is created with Visual Studio 2008 and it adds a manifest automatically which looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>

What should I change to make my dialog use the current theme instead of Windows 98 look? I've read about isolation awareness, but that didn't seem to work either.

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

4

As you've discovered, adding the manifest is only half of the battle. You also need to call the InitCommonControlsEx function when your add-in initializes, before any controls are created. This is necessary to register the window classes for the common controls you use.

And just in case you're skeptical of the documentation, Microsoft's Raymond Chen posted an article on his blog a while back addressing precisely this issue.

If you have any other issues, check this article: How to apply Windows XP themes to Office COM add-ins

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • I added InitCommonControlsEx in the constructor of my addin class, but there didn't seem to be any effect. Am I doing something wrong? CConnect::CConnect() { INITCOMMONCONTROLSEX initcommctrl = { sizeof(initcommctrl), 0xffffffff }; InitCommonControlsEx(&initcommctrl); MessageBox(0,0,0,0); } The MessageBox shown here isn't themed. – sashoalm Jan 19 '11 at 16:26
  • I also added #define ISOLATION_AWARE_ENABLED 1 to the top of my stdafx but still no luck. – sashoalm Jan 19 '11 at 16:42
  • I just realized that InitCommonControlsEx fails returning FALSE, but a quick googling a forum post explaining that the problem does come from the manifest, and that I should add this pragma to my code: #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' ""version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") That did the trick :) In fact it turns out INITCOMMONCONTROLSEX isn't needed after all, probably something with the manifest file wasn't right in my project. But thank you anyway :) – sashoalm Jan 19 '11 at 16:55
  • @satuon: I'm glad you got the problem solved. But I question your comment that it "turns out INITCOMMONCONTROLSEX isn't needed after all". The [blog post I linked to](http://blogs.msdn.com/b/oldnewthing/archive/2005/07/18/439939.aspx) in fact explains precisely why this *is* required, even if it *appears* to work without it. – Cody Gray - on strike Jan 20 '11 at 04:51
  • Thanks, I added the InitCommonControlsEx back. I had assumed it was called by the framework itself (since everything worked) but when I placed a breakpoint on it I saw it wasn't being called. One more question - I pass ICC_STANDARD_CLASSES as the flags in INITCOMMONCONTROLSEX, is that correct? – sashoalm Jan 20 '11 at 08:10
  • @satuon: It depends on which controls you are using in your application. The complete list of flags you can pass is available [here](http://msdn.microsoft.com/en-us/library/bb775507.aspx). – Cody Gray - on strike Jan 20 '11 at 08:13