windowswinapiwindow-messages

WM_MSO_BROADCASTCHANGE value


What's the value for WM_MSO_BROADCASTCHANGE, and how would I figure it out for myself next time?


Solution

  • A late answer, I know, but as it happens I was recently looking for the answer to this question myself, so this may help other errant Googlers...

    Turns out that "WM_MSO_BROADCASTCHANGE" has no set value. You obtain a value for it dynamically by calling RegisterMessage. See http://msdn.microsoft.com/en-us/library/ms644947(v=vs.85).aspx

    Note that in this particular case MS Office appears to broadcast the message, so only other top-level windows will receive it.

    In general, you can use a tool like Spy++ (provided with Visual Studio and probably the Windows Platform SDKs too) to see what the value of a message is. In this case, Spy++ will also log that it's a registered message.

    To listen for it you might write some C# code, for example, that looks like this.

    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
      ....
    class ThemeChangeCatcherpublic : Form
        {
            private const string WM_MSO_BROADCAST_NAME = "WM_MSO_BROADCASTCHANGE";
    
            private int WM_MSO_BROADCASTCHANGE = 0;
    
            internal static class NativeMethods
            {
                [DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
                internal static extern int RegisterWindowMessage(string lpString);
            }
    
            protected override void OnHandleCreated(EventArgs e)
            {
                base.OnHandleCreated(e);
    
                WM_MSO_BROADCASTCHANGE = NativeMethods.RegisterWindowMessage(WM_MSO_BROADCAST_NAME);
            }
    
            protected override void WndProc(ref Message m)
            {
                if (m.Msg == WM_MSO_BROADCASTCHANGE)
                    MessageBox.Show("gotcha!");
                else
                    base.WndProc(ref m);    
            }        
        }