Friends its really giving me a great head ache about the problem I am facing for the couple of days…Its simple…I want to communicate between two/more dialog boxes for example if there is a variable CString test..I want this test variable to be common for the dialogs/classes(considering each dialog having separate classes)…I tried lot methods, everything failed..atlast I tried this WM_COPYDATA method…even now, am not achieve what i wanted to do…
Sender Class:
#define ORGININFO 1
typedef struct ShareMessage
{
CString mydata;
int myValue;
}MYDATA;
void CCopyDataDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
MYDATA myData;
COPYDATASTRUCT cData;
myData.mydata.SetString(L"Rakesh");
cData.dwData = ORGININFO;
cData.cbData = sizeof(myData);
cData.lpData = &myData;
HWND hwnd = (HWND)FindWindow(L"Dialog1",L"Test");
SendMessageA(m_hWnd,WM_COPYDATA,(WPARAM)hwnd,(LPARAM)(LPVOID)&myData);
Dialog1 dlg;
dlg.DoModal();
}
Receiver class:
#define iMessage 1
typedef struct MyDatas
{
CString myData;
int myint;
}DATA;
PCOPYDATASTRUCT pData;
LRESULT Dialog1::WindowProc(UINT message,WPARAM wParam,LPARAM lparam)
{
if(WM_COPYDATA != NULL)
pData = (PCOPYDATASTRUCT)lparam;
switch(pData->dwData)
{
case iMessage:
MessageBoxA((HWND)AfxGetInstanceHandle(),(LPCSTR)(LPCTSTR)((DATA*)(pData->lpData))->myData,(LPCSTR)L"Test",MB_OK);
}
return 0;
}
in the above I dont know what is the mistake I am doing but its not receiving the data from the CCopyDialog class…Please help me with this…
I avoided to use WinProc..Instead of that I wrote a normal function(CopyData) in the class Dialog11..Created a modeless dialog in the class CCopyDialog1.. and called that function(CopyData)..It worked..Please check the below code…
Basically when compared to my previous code(code in my question)…theres lot of difference/mistakes..
1.In the sendmessage i passed the structure instead of COPYDATASTRUCT..
2.Called FindWindow before calling the Dialog1 window..
3.Used the function WinProc function to receive the message..which was very hard to make it work..then avoided that and used a normal function
4.Didnt pass a proper window handle…
the above all are corrected by Bob Moore…credit goes to him….