two dialogs, global variables? (vc++ 6.0 mfc)
-
i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks
-
i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks
guess what, i've just submitted a new article about that (around last thursday), but i'm still waiting for it to be published (editors have a lot of work)... when it comes out, don't hesitate to check it (called Dialogs Communication - Or the art of exchanging data...). for your input, transmit your infos thru the child dialog's constructor
[VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]
-
i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks
rolfhorror wrote:
how can these two dialogs share variables?
Do they really need to? If so, they are inherently tied together from that point forward. That's not necessarily a bad thing, but it does keep the child dialog from being re-used. Several solutions exist:
void CMainDialog::SomeAction()
{
CChildDialog dlg(m_var1, m_var2);
// or
dlg.m_var1 = m_var1;
dlg.m_var2 = m_var2;
// or
dlg.SetVar1(m_var1);
dlg.SetVar2(m_var2);if (dlg.DoModal() == IDOK) { m\_var1 = dlg.m\_var1; m\_var2 = dlg.m\_var2; // or m\_var1 = dlg.GetVar1(); m\_var2 = dlg.GetVar2(); }
}
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks
Is this helpfuls you can insert this code to child dialog after user insert his text on your editbox.
After insert text to editbox on the child dialog you can get this string and use of this code (if you dont need to global cstring)
CMain *m_Main=(CMain*)GetParent();
m_Main->m_EditControl.SetWindowText();
WhiteSky
-
i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks
one solution is to pass a pointer (this) of the parent dialog to the child dialog :
//...
MyChildDialog dlg( this );
dlg.DoModal();But that would force a "coupling" dependance between both dialogs; maybe it's ok for your particular situation.
Maximilien Lincourt Your Head A Splode - Strong Bad
-
one solution is to pass a pointer (this) of the parent dialog to the child dialog :
//...
MyChildDialog dlg( this );
dlg.DoModal();But that would force a "coupling" dependance between both dialogs; maybe it's ok for your particular situation.
Maximilien Lincourt Your Head A Splode - Strong Bad
thanks alot guys, i'll try your coding.