朋友们,这几天我面临的问题真的让我很头疼......它很简单......我想在两个/多个对话框之间进行通信,例如,如果有一个变量 CString 测试......我希望这个测试变量对于对话框/类是通用的(考虑到每个对话框都有单独的类)......我尝试了很多方法,一切都失败了......最后我尝试了这个 WM_COPYDATA 方法......即使现在,我也没有达到我想要的去做...
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();
}
接收器类:
#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;
}
在上面我不知道我在做什么错误,但它没有从 CCopyDialog 类接收数据......请帮助我......