在一个对话框(CMyDlg)点击按钮后弹出另外一个对话框(setingdlg),我试图后一个对话框的数据能传给前一个代码如下:
void CMyDlg::OnSeting()
{
// TODO: Add your control notification handler code here int nResponce;
nResponce=setingdlg.DoModal();
if(nResponce==IDOK)
{
int ItemCount;
ItemCount=setingdlg.nItem;
TRACE("The num is %d",ItemCount);
BOOL bl;
bl=setingdlg.m_tstptctl.GetCheck(2);
}
}其中nItem是setingdlg中的public 整型变量,m_tstptctl是它上面的clistctrl控件,当然也是public
运行后,nItem能传给ItemCount,但是到了到了bl=setingdlg.m_tstptctl.GetCheck(2);就出现debug assertion failed.
请问有什么方法才能把子对话框控件(不光是listctrl)上的数据传给父对话框?谢谢!
void CMyDlg::OnSeting()
{
// TODO: Add your control notification handler code here int nResponce;
nResponce=setingdlg.DoModal();
if(nResponce==IDOK)
{
int ItemCount;
ItemCount=setingdlg.nItem;
TRACE("The num is %d",ItemCount);
BOOL bl;
bl=setingdlg.m_tstptctl.GetCheck(2);
}
}其中nItem是setingdlg中的public 整型变量,m_tstptctl是它上面的clistctrl控件,当然也是public
运行后,nItem能传给ItemCount,但是到了到了bl=setingdlg.m_tstptctl.GetCheck(2);就出现debug assertion failed.
请问有什么方法才能把子对话框控件(不光是listctrl)上的数据传给父对话框?谢谢!
比如
BOOL m_bl;
void CMyDlg::OnSeting()
{
// TODO: Add your control notification handler code here int nResponce;
nResponce=setingdlg.DoModal();
if(nResponce==IDOK)
{
int ItemCount;
ItemCount=setingdlg.nItem;
TRACE("The num is %d",ItemCount);
BOOL bl;
bl=setingdlg.m_b1;//m_b1在OnOk置值
// 此处不能再访问对话框的控件变量了,因为对话框已经销毁了
}
}
你这样做肯定不行 都OK了 就没有了setingdlg这个对象了
CDocument * pDocActive = ((CFrameWnd *)(AfxGetApp()->m_pMainWnd))->GetActiveDocument();
CMyDlgDoc * m_pDoc = (CMyDlgDoc *)pDocActive;然后用指针m_pDoc调用数据或存储数据
int m_nItemCount;在setingdlg对话框对应的类中
先获取想要传递的变量值,比如是nItemCount, 在该对话框关闭之前CMyDlg * pParentDlg = (CMyDlg *)GetParent();
pParentDlg->m_nItemCount = nItemCount;
时对话框对象已经释放啦。所以不能访问
最好用全局变量