Tuesday 15 March 2011

mfc - How do I Send global value between two dialog -


For now, follow two of my two structures like

  GetDialog. H struct GetDlgData {int nStatic1; Int Nastatic 2; CSTing straight 1; CSTing straight2; }; GetDlgData g_structData; Seetic m_staticGet1; Seetic m_staticGet2; CEdit m_editGet1; CEdit m_editGet2; Zero SetGetValue (); GetDlgData GetGetValue () {Return g_structData;} Virtual BOOL OnInitDialog (); DoModalGetDataDlg.h Configuration DoData {int nStatic1; Int Nastatic 2; CSTing straight 1; CSTing straight2; }; Seestic m_staticDo1; Cstcat m_staticDo2; CEdit m_editDo1; CEdit m_editDo2; DoData g_structData; Zero seto value (); DoData GetDoValue () {Return g_structData;} afx_msg Zero onBnClickedButtonDo ();   

The value should be sent to another dialog, which is saved in the Stretch

  DoModalGetDataDlg.cpp zero CDoModalGetDataDlg :: SetDoValue () {CString StrTemp; StrTemp.Empty (); M_staticDo1.GetWindowText (strTemp); G_structData.nstatic1 = _ttoi (strTemp); StrTemp.Empty (); M_staticDo2.GetWindowText (strTemp); G_structData.nstatic2 = _ttoi (strTemp); M_editDo1.GetWindowText (g_structData.strEdit1); M_editDo2.GetWindowText (g_structData.strEdit2); } Zero CDoModalGetDataDlg :: OnBnClickedButtonDo () {DoData structData; SetDoValue (); CGetDialog GetDlg; GetDlg.DoModal (); }   

Get data in GetDlg.cpp, when the dialog init

  BOOL CGetDialog :: OnInitDialog () {CDialog :: OnInitDialog (); SetGetValue (); Return TRUE; // True TRUE unless you set the focus to control} Zero CGetDialog :: SetGetValue () {CDoModalGetDataDlg DoDlg (AfxGetMainWnd ()); Memcpy (& amp; g_struct data, & DoDlg.GetDoValue (), sizeof (GetDlgData)); CString strTemp; StrTemp.Empty (); StrTemp.Format (_T ("% d"), g_structData.nstatic1); M_staticGet1.SetWindowText (strTemp); StrTemp.Empty (); StrTemp.Format (_T ("% d"), g_structData.nstatic2); M_staticGet2.SetWindowText (strTemp); M_editGet1.SetWindowText (g_structData.strEdit1); M_editGet2.SetWindowText (g_structData.strEdit2); }   

But the value is random, in the Memkpy area. How do I solve it ...

Thank you very much!

Your call CDoModalGetDataDlg DoDlg (AfxGetMainWnd ()); Creates a new example of CDoModalGetDataDlg , it does not "connect" to the current instance of that class.

You can set the value before calling DoModal () , such as

  zero CDoModalGetDataDlg :: OnBnClickedButtonDo () {DoData structData ; SetDoValue (); CGetDialog GetDlg; Memcpy (& amp; GetDlg.g_struct Data, & GetDoValue (), sizeof (GetDlgData)); GetDlg.DoModal (); }    

No comments:

Post a Comment