Enabling XP visual styles (themes) in COM Addins

C

Casey

Hi,

I found the following KB article on MSDN that shows how to apply XP themes
to Office COM Addins and it works:
http://support.microsoft.com/kb/830033/en-us?spid=2488&sid=251

The solution suggests wrapping all your forms with a using block that pushes
a themed activation context before any of your controls are created.
However, we have many forms, messageboxes, etc. and it is cumbersome to wrap
each one with a using block. So, I tried creating one instance of the
EnableThemingInScope (activating the themed activation context) in the
Connect method of my addin, then hold onto the reference and dispose of it
in the OnDisconnection method. It worked somewhat in OfficeXP (2002), but
did not work and caused a crash in Office2003 when trying to dispose
(deactivate the activation context). Any ideas why? Is there an easier way
to enable theming in Office COM Addins? I guess I need to know more about
activation contexts.

Thanks,
Casey

ps- I noticed in another post that someone else launches there forms from an
exe so they can use a manifest to apply XP themes, but that is not an
appropriate solution for us.
 
X

XL-Dennis

Casey,

I've find out that the following snippet VB.NET code in the OnConnection
event gives the XP style in a smooth way:

System.Windows.Forms.Application.EnableVisualStyles()
System.Windows.Forms.Application.DoEvents()

I've made some very limited test by switching themes and it seems to work
(at least on my developing machine).
 
C

Casey

Dennis,

Thank you very much, that worked! Obviously can't use a manifest file for
Office COM Addin, but for some reason I had already ruled out
EnableVisualStyles as well. The KB article certainly threw me off.

Is the DoEvents necessary? Isn't that normally for heavier processing
during loops? I noticed it worked without it.

Thanks again,
Casey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top