Yes it is possible. I had to solve a similar problem with one of my extensions ... The current topic is stored in the Windows registry; so I applied the following utility class.
public enum VsTheme { Unknown = 0, Light, Dark, Blue } public class ThemeUtil { private static readonly IDictionary<string, VsTheme> Themes = new Dictionary<string, VsTheme>() { { "de3dbbcd-f642-433c-8353-8f1df4370aba", VsTheme.Light }, { "1ded0138-47ce-435e-84ef-9ec1f439b749", VsTheme.Dark }, { "a4d6a176-b948-4b29-8c66-53c97a1ed7d0", VsTheme.Blue } }; public static VsTheme GetCurrentTheme() { string themeId = GetThemeId(); if (string.IsNullOrWhiteSpace(themeId) == false) { VsTheme theme; if (Themes.TryGetValue(themeId, out theme)) { return theme; } } return VsTheme.Unknown; } public static string GetThemeId() { const string CategoryName = "General"; const string ThemePropertyName = "CurrentTheme"; string keyName = string.Format(@"Software\Microsoft\VisualStudio\11.0\{0}", CategoryName); using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName)) { if (key != null) { return (string)key.GetValue(ThemePropertyName, string.Empty); } } return null; } }
Good; it just helps to determine the current settings ... listening to the subject of the modified notification is a bit more complicated. After downloading the package, you should get an IVsShell instance through the DTE; If you have this object, you can use the AdviceBroadcastMessages method to subscribe to event notifications. You must provide an object of type IVsBroadcastMessageEvents ...
I do not want to publish the entire implementation, but the following lines may illustrate the key scenario ...
class VsBroadcastMessageEvents : IVsBroadcastMessageEvent { int IVsBroadcastMessageEvent.OnBroadcastMessage(uint msg, IntPtr wParam, IntPtr lParam) { const uint WM_SYSCOLORCHANGE = 0x15; if (msg == WM_SYSCOLORCHANGE) {
Consider implementing IDisposable for this type to be able to unsubscribe from the event source when the package is unloaded.
Here's how I sign up for event notifications ...
class ShellService { private readonly IVsShell shell; private bool advised; public ShellService(IVsShell shellInstance) { this.shell = shellInstance; } public void AdviseBroadcastMessages(IVsBroadcastMessageEvents broadcastMessageEvents, out uint cookie) { cookie = 0; try { int r = this.shell.AdviseBroadcastMessages(broadcastMessageEvents, out cookie); this.advised = (r == VSConstants.S_OK); } catch (COMException) { } catch (InvalidComObjectException) { } } public void UnadviseBroadcastMessages(uint cookie) { ... } }
Save cookie value; you will need it to unsubscribe successfully.
Hope that helps (-: