vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
use :: SendMessage to a window of application B. and you *must* use a WM_COPYDATA message. eg.
// ...
HWND window = ::FindWindow( 0, L"app B's window title" ) ;
if( IsWindow(window) )
{
TCHAR message[] = L"Hello World" ;
COPYDATASTRUCT data = { 0, sizeof(message), message } ;
::SendMessage( window, WM_COPYDATA, 0 /* your window's handle */, &data ) ;
}
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
sending data:
// ...
HWND window = ::FindWindow( 0, L"app B's window title" ) ;
if( ::IsWindow(window) )
{
TCHAR message[] = L"Hello World" ;
COPYDATASTRUCT data = { 0, sizeof(message), message } ;
::SendMessage( window, WM_COPYDATA,
WPARAM( 0 /* your window's handle */ ),
LPARAM( &data ) ) ;
}
//...
receiving data:
from your code it appears that you are using MFC;
a. in your CMainFrame (the top window) class (mainfrm.h) add,
class CMainFrame : public CFrameWnd
{
// ...
afx_msg LRESULT OnCopyData(WPARAM, LPARAM); // *** add this ***
// ...
};
b. in mainfrm.cpp, add a mesage map entry
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
// ... other message map entries
ON_MESSAGE( WM_COPYDATA, OnCopyData ) // *** add this ***
END_MESSAGE_MAP()
c. in mainfrm.cpp, implement the message handler
LRESULT CMainFrame::OnCopyData( WPARAM wParam, LPARAM lParam )
{
COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam ;
// use the data
// eg.
::AfxMessageBox( LPCTSTR(pcds->lpData) ) ;
// if you want to keep the data for later use, you must
// allocate memory yourself and do a deep copy of the data
// ...
return 0 ;
}
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287