请问RegisterWindowMessage函数的干什么用的,什么时候使用?
还有下面代码是什么意思?
      UINT nMsgID = RegisterWindowMessage(g_szCustomWndMsg);
PostMessage(HWND_BROADCAST, nMsgID, 0, 0);
HWND_BROADCAST是什么东东?麻烦解释一下,先谢了!!

解决方案 »

  1.   

    RegisterWindowMessage保证消息的唯一性。
    HWND_BROADCAST:The message is posted to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows. The message is not posted to child windows.
      

  2.   

    假设程序A要跟程序a1,a2通讯,在代码里写死消息用0xC001,广播消息PostMessage(HWND_BROADCAST,0xC001。
    但是比如碰巧程序B要跟程序b1,b2通讯,不巧代码里也是用的消息0xC001,那么A程序PostMessage(HWND_BROADCAST,0xC001,就有问题了,因为这样b1,b2也会收到消息0xC001,而且他们
    会以为是B发出的消息。
    有了RegisterWindowMessage,程序A,a1,a2用一个字符串注册一个消息作为它们之间通讯的专用消息,比我我们使用GUID,这样可以保证与程序B,b1,b2使用的专用消息不
    一样,这样广播消息就不会引起混乱。因为RegisterWindowMessage保证同一时刻用不同字符串注册消息会得到不同的消息,用同一字符串注册一定得到同一个消息。“不同字符串”可以很容易用GUID实现
      

  3.   

    HWND_BROADCAST的作用:通知系统刷新的
    比如修改注册表后,隐藏托盘图标后,都可以发送此消息:
    // 刷新托盘
    ::SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
      

  4.   

    LRESULT SendMessage(          HWND hWnd,
        UINT Msg,
        WPARAM wParam,
        LPARAM lParam
    );
    ParametershWnd
    [in] 
    Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.