如何捕获广播消息?

najzni 2004-09-08 04:02:47
在一个进程的线程中::PostMessage(HWND_BROADCAST,WM_TEST,0,0);
那么在另一个进程中如何捕获该消息?
...全文
122 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Anikan 2004-09-08
  • 打赏
  • 举报
回复
你必须在TOP_LEVEL的窗口中(不是子窗口)捕获这个消息。具体的你可以查看MSDN对PostMessage 中当HWND == HWND_BROADCAST的解释。
wqs_qiu_shi 2004-09-08
  • 打赏
  • 举报
回复
两个程序中要注册同样的消息名称

UINT nMsgID = RegisterWindowMessage("wqs");
::PostMessage(HWND_BROADCAST,nMsgID,wParam,lParam);

------------------------
recv:
m_nMsgID = RegisterWindowMessage("wqs");
PreTranslateMessage(MSG* pMsg)中:
if( pMsg->message == m_nMsgID )
AfxMessageBox("ok!");
najzni 2004-09-08
  • 打赏
  • 举报
回复
试过,这样好像不行。
stevecrisewu 2004-09-08
  • 打赏
  • 举报
回复
GetMessage
The GetMessage function retrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a posted message is available for retrieval.

Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning.

BOOL GetMessage(
LPMSG lpMsg, // message information
HWND hWnd, // handle to window
UINT wMsgFilterMin, // first message
UINT wMsgFilterMax // last message
);
Parameters
lpMsg
[out] Pointer to an MSG structure that receives message information from the thread's message queue.
hWnd
[in] Handle to the window whose messages are to be retrieved. The window must belong to the calling thread. The following value has a special meaning. Value Meaning
NULL GetMessage retrieves messages for any window that belongs to the calling thread and thread messages posted to the calling thread using the PostThreadMessage function.


wMsgFilterMin
[in] Specifies the integer value of the lowest message value to be retrieved.
wMsgFilterMax
[in] Specifies the integer value of the highest message value to be retrieved.
Return Values
If the function retrieves a message other than WM_QUIT, the return value is nonzero.

If the function retrieves the WM_QUIT message, the return value is zero.

If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid window handle or lpMsg is an invalid pointer. To get extended error information, call GetLastError.

Warning Because the return value can be nonzero, zero, or -1, avoid code like this:

while (GetMessage( lpMsg, hWnd, 0, 0)) ...
The possibility of a -1 return value means that such code can lead to fatal application errors.

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧