Click here to Skip to main content
15,749,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application,there are two dialogs and I am tyring to update value of second dialog control variable on the event occurred in first dialog.
First of all I create an object of the second dialog and trying to call SetWindowText() method on one of the control variables of it,but it throws exception.When I debug application,second dialog object shows Hwnd values=0x0000000 in Autos section.Below I paste some code snippest,please suggest required changes.
How to solve this problem?

void CFirstDlg::OnBnClickedConnect()
      CSecondDlg* dlg=new CSecondDlg(); //Create object of second dialog
      dlg->mtxtTS1.SetWindowTextW(L"0");  //Trying to access control variable and set properties on it
      delete dlg;
Updated 14-Oct-15 22:27pm

1 solution


dlg->mtxtTS1.SetWindowTextW(L"0"); //Trying to access control variable and set properties on it
You cannot do that, because the CDialog object is actually created but it has no window associated (because, assuming a modal dialog, the window is created only when DoModal is called).
You should instead set a member variable of CSecondDlg (say m_szText) and then, in CSecondDlg::OnInitDialog use it to actually chage the window text).

By the way, have a look at this oldie-goldie toxcct's article: Dialogs Communication[^].
Share this answer
Venkat Raghvan 15-Oct-15 5:28am    
I am trying to do that way but it's not working.One thing is that,second dialog is act as child of First dialog and it is added into the tab control of first dialog.Can this affect the behavior of GUI?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900