
Trying to send a message from one app to another
Quote:
> I am also having the same problem.
> see message "Sending a message from one app to another on NT" dated 18/7/97
> I have tried DDE_EXECUTE, WM_COPYDATA and what you have done, to no success
> >I am using Visual C++ 4.2 and Windows NT. I am programming with the MFC.
> >I am trying to send a message from one app to another. I have used the
> >Win32 API PostMessage and SendNotifyMessage using HWND_BROADCAST for the
> >first parameter to send the message. I placed the message handler in
> >CMainFrame and used ON_MESSAGE in the message map. The message does not
> >appear to be getting to it's destination. Any advice would be greatly
> >appreciated. Thank you.
PostMessage with a user-defined message or SendMessage with WM_COPYDATA
work fine. First you have to control the receiving app's window class
name by calling AfxRegisterClass in InitInstance and setting the
cs.lpszClass parameter in the mainframe's PreCreateWindow. Check it
with Spy++ to make sure you have set the mainframe's class name.
Then the sending app does:
#define WM_MY_MESSAGE (WM_APP + 1234)
CWnd* pOtherApp = FindWindow(TARGET_APP_WINCLASS_STRING, 0);
if (pOtherApp)
{ pOtherApp->PostMessage(WM_MY_MESSAGE, n1, n2);
-- or --
pOtherApp->SendMessage(WM_COPYDATA, (WPARAM)m_hWnd, (LPARAM)&cds);
}
and the receiving app uses ON_MESSAGE in the mainframe message map (put
it outside of the class wizard comments, just before END_MESSAGE_MAP().