问题描述
在SDIexample中,我有
In an SDIexample in which i have
SDIexampledoc.h
SDIexampledoc.h
SDIexampleview.h
SDIexampleview.h
SDIexampleapp.h
SDIexampleapp.h
SDImainframe.h
SDImainframe.h
我在SDIexample中添加了2个对话框
i HAve added 2 dialogs in SDIexample
1. IDD_Dialog1。
1. IDD_Dialog1.
2. IDD_Dialog2。
2. IDD_Dialog2.
我正在做的是我得到一个变量,让我说来自dialog1中编辑控件的用户m = 10.
what i am doing is i am getting a variable lets say m=10 from user in edit control in dialog1.
现在我想要在关闭dialog1之前将此变量存储在exampledoc.h中。因此,当我调试dialog2时,我可以从doc.h中检索m的值。
now i want to store this variable in exampledoc.h before closing dialog1. so that when i debug dialog2 i can retrieve the value of m from doc.h.
我知道我可以通过发送消息来实现这一点。
i get to know that i can do this through send message.
但如何准确编码。
推荐答案
你可以使用CopyData消息。
you can use CopyData message.
在你的对话框中,你可以发送如下:
In your Dialog, you can send as following:
m=10; // user input
COPYDATASTRUCT cpdata;
cpdata.cbData = 999; //函数标识符
cpdata.dwData = 1; //消息类型
cpdata.lpData =(PVOID)& m; //这个你要保存在文件
AfxGetMainWnd() - > SendMessage(WM_COPYDATA,(WPARAM)0,(LPARAM)(LPVOID)& cpdata);
COPYDATASTRUCT cpdata;cpdata.cbData = 999; // function identifiercpdata.dwData = 1; // message typecpdata.lpData = (PVOID)&m; // this you want to save in documentAfxGetMainWnd()->SendMessage(WM_COPYDATA, (WPARAM)0, (LPARAM)(LPVOID)&cpdata);
在CMainframe中,你覆盖OnCopyData(在类向导中添加WM_COPYDATA的事件处理程序):
In CMainframe, you overwrite OnCopyData (add the event handler for WM_COPYDATA in class wizard):
BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
if (pCopyDataStruct && pCopyDataStruct->cbData == 999 && pCopyDataStruct->dwData == 1)
{
GetDocument()->m = *(pCopyDataStruct->lpData);
return TRUE;
}
return CSDIFrameWndEx::OnCopyData(pWnd, pCopyDataStruct); // I don't know the base class but class wizard does it for you
}
问候,Guido
Regards, Guido
这篇关于SDI MFC C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!