MFC学习(18)MFC中利用HWND_BROADCAST 向其它所有窗口广播消息

利用HWND_BROADCAST可以向其它进程,或DLL文件的窗口等发送消息.

在MSDN中如此描述的:

    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.
遮挡的窗口也可收到消息.

首先要定义消息:

必须使用RegisterWindowMessage,是Windows的注册消息变量;

如:

static UINT NEAR WM_OVER_LOAD= RegisterWindowMessage(_T("OVER_LOAD"));

其次宏声明为
ON_REGISTERED_MESSAGE(WM_OVER_LOAD, OnOverLoad) 函数声明和普通消息的函数声明一样
afx_msg LRESULT OnOverLoad(WPARAM wParam, LPARAM lParam);

发送消息例如:

::SendMessage( (HWND)HWND_BROADCAST,WM_OVER_LOAD, 参数1 ,参数2 );

::PostMessage( (HWND)HWND_BROADCAST,WM_OVER_LOAD, 参数1 ,参数2 );

如此所有的注册了此消息的窗口都可以收你发的消息了


你可能感兴趣的:(MFC)