Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

edit control in different class

Status
Not open for further replies.

mangocinn

Programmer
Jul 26, 2001
66
0
0
US
Hi.

I want to retrieve the value of an edit control from a class that is different from the one that is controlling the dialog.

Class A displays dialogB controlled by Class B.
EditControl is in dialog B.

When I use GetDlgItemText from Class B OnButtonClick event I can retrieve the value of the edit control.

However I try to use GetDlgItemText from Class A and I get a debug assertion error... ?? Anyone know what I am missing?
 
Within Class A, make sure you are calling b.GetDlgItemText (where b is your Class B object) instead of just GetDlgItemText. If you didn't call B's method, it would look for that dlg item in A, where it does not exist, which would cause the problem.
 
timmay,

Yes I am using the GetDlgItemText on the class B object.

Here is the code that I use within my class A function.

classB dlg;
INT_PTR dlgResponse = dlg.doModal();
if (dlgResponse == IDOK)
{
char localDir[128];

dlg.GetDlgItemText(IDC_MY_EDIT, localDir, 128);
}

I think I know why I am getting the assertion error. It looks like the dialog gets closed before it reaches the GetDlgItemText call. How can I prevent that?
 
Yeah, that's the problem. In your dialog's OnOK or OnCancel function, just record in a member variable what the text is, then just access that variable in your code instead of using GetDlgItemText. Since you're using MFC, just bind a CString to that edit box and it should automatically be the correct value without you telling it to update.
 
Yes, timmay thanks.... that is what I ended up doing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top