WM_MSO_BROADCASTCHANGE value

扶醉桌前 提交于 2019-12-12 01:34:28

问题


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


回答1:


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);    
        }        
    }



回答2:


In most cases, I would say use Google or MSDN. Searching for WM_TIMER on MSDN turns up this as the #1 answer:

http://msdn.microsoft.com/en-us/library/ms644902(VS.85).aspx

and so we have:

#define WM_TIMER                        0x0113

In your case, a search for that string on Google turns up just two matches, that show differing values - so I cannot think of what to tell you. Is this in a third-party library whose documentation or code would tell you the value? It has to be defined in a header file somewhere, if it's correct, or nobody can use it in their code. Then again, perhaps hiding the value is the intention. Is this some internal-only Windows Message used by an addin?



来源:https://stackoverflow.com/questions/4102389/wm-mso-broadcastchange-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!