MFC - how to get an edit box text from another dialog?? (Constructor)
-
Hi there, I have an edit box control in a dialog and a button which opens another dialog... I need to learn how can I use main dialog's aditbox text in opened one's editbox (Data transfer)... Please I need urgent help... :(
-
Hi there, I have an edit box control in a dialog and a button which opens another dialog... I need to learn how can I use main dialog's aditbox text in opened one's editbox (Data transfer)... Please I need urgent help... :(
Howdy, you'll need the HWND of each dialog and the INT identifier of each control, or you'll need the HWND of each edit control.I'll assume the first.
HWND editSrc, editDst; char \*szBuffer; int stringLength; editSrc = GetDlgItem(dlg1, IDC\_EDITBOX1); editDst = GetDlgItem(dlg2, IDC\_EDITBOX2); stringLength = GetWindowTextLength(editSrc); szBuffer = new char\[stringLength+1\]; ZeroMemory(szBuffer, stringLength+1); GetWindowText(editSrc, szBuffer, stringLength); SetWindowText(editDst, szBuffer); delete szBuffer;
-
Hi there, I have an edit box control in a dialog and a button which opens another dialog... I need to learn how can I use main dialog's aditbox text in opened one's editbox (Data transfer)... Please I need urgent help... :(
Keep a public CString member variable in Child dialog class, set the member variable before calling the DoModal() or Create function of child dialog. Call SetWindowText of edit control in InitDialog. for. eg If CMainDlg is your Main dialog class and CChildDialog be the child. in header of CChildDialog you declare a public member variable to hold the string
class CChildDialog : public CDialog
{
public :
CString m_strText;
}and in your button click function of CMainDlg do this
void CMainDlg::OnClick_Button()
{CChildDialog oChildDlg;
oChildDlg.m_strText = strText; // This should be the edit box value
oChildDlg.DoModal();
}Set the variable value in CChildDialog's OnInitDialog as
CChildDialog::OnInitDialog()
{
SetDlgItemText(ID_OF_YOUR_EDIT, m_strText);
}You can also set the text by modifying your constructor of CChildDialog, such as
CChildDialog::CChildDialog(CString strText)
-
Hi there, I have an edit box control in a dialog and a button which opens another dialog... I need to learn how can I use main dialog's aditbox text in opened one's editbox (Data transfer)... Please I need urgent help... :(
You could use
GetDlgItemText()
[^] and its counterpartSetDlgItemText()
.Unrequited desire is character building. OriginalGriff
-
Howdy, you'll need the HWND of each dialog and the INT identifier of each control, or you'll need the HWND of each edit control.I'll assume the first.
HWND editSrc, editDst; char \*szBuffer; int stringLength; editSrc = GetDlgItem(dlg1, IDC\_EDITBOX1); editDst = GetDlgItem(dlg2, IDC\_EDITBOX2); stringLength = GetWindowTextLength(editSrc); szBuffer = new char\[stringLength+1\]; ZeroMemory(szBuffer, stringLength+1); GetWindowText(editSrc, szBuffer, stringLength); SetWindowText(editDst, szBuffer); delete szBuffer;
See my response for simpler functions.
Unrequited desire is character building. OriginalGriff
-
Keep a public CString member variable in Child dialog class, set the member variable before calling the DoModal() or Create function of child dialog. Call SetWindowText of edit control in InitDialog. for. eg If CMainDlg is your Main dialog class and CChildDialog be the child. in header of CChildDialog you declare a public member variable to hold the string
class CChildDialog : public CDialog
{
public :
CString m_strText;
}and in your button click function of CMainDlg do this
void CMainDlg::OnClick_Button()
{CChildDialog oChildDlg;
oChildDlg.m_strText = strText; // This should be the edit box value
oChildDlg.DoModal();
}Set the variable value in CChildDialog's OnInitDialog as
CChildDialog::OnInitDialog()
{
SetDlgItemText(ID_OF_YOUR_EDIT, m_strText);
}You can also set the text by modifying your constructor of CChildDialog, such as
CChildDialog::CChildDialog(CString strText)
-
You could use
GetDlgItemText()
[^] and its counterpartSetDlgItemText()
.Unrequited desire is character building. OriginalGriff
I did it as Mahdu replied and by your hint... like
void mainform::OnBnClickedButton2()
{
GetDlgItemText(IDC_EDIT1,newform.strtext);
}BOOL newform::OnInitDialog()
{
SetDlgItemText(IDC_EDIT1, strtext);
}THANKS TO YOU ALL FOR REPLIES PEOPLE!!! YOU ARE GREAT... :))
-
See my response for simpler functions.
Unrequited desire is character building. OriginalGriff
-
Hi there, I have an edit box control in a dialog and a button which opens another dialog... I need to learn how can I use main dialog's aditbox text in opened one's editbox (Data transfer)... Please I need urgent help... :(
How about something like:
CMainDlg::OnButtonClick()
{
CString strText;
m_edit.GetWindowText(strText);CSecondDlg dlg; dlg.setData(strText); dlg.DoModal();
}
CSecondDlg::setData( LPCTSTR lpszText )
{
m_strText = lpszText;
}CSecondDlg:OnInitDialog()
{
m_edit.SetWindowText(m_strText);
}I'm a big fan of weak coupling, so tying these two dialogs together like this would not be my first choice. I would opt for a "data transfer" or "liaison" class instead. This is a one-instance class where you would put all of your shared data.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
How about something like:
CMainDlg::OnButtonClick()
{
CString strText;
m_edit.GetWindowText(strText);CSecondDlg dlg; dlg.setData(strText); dlg.DoModal();
}
CSecondDlg::setData( LPCTSTR lpszText )
{
m_strText = lpszText;
}CSecondDlg:OnInitDialog()
{
m_edit.SetWindowText(m_strText);
}I'm a big fan of weak coupling, so tying these two dialogs together like this would not be my first choice. I would opt for a "data transfer" or "liaison" class instead. This is a one-instance class where you would put all of your shared data.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
How about something like:
CMainDlg::OnButtonClick()
{
CString strText;
m_edit.GetWindowText(strText);CSecondDlg dlg; dlg.setData(strText); dlg.DoModal();
}
CSecondDlg::setData( LPCTSTR lpszText )
{
m_strText = lpszText;
}CSecondDlg:OnInitDialog()
{
m_edit.SetWindowText(m_strText);
}I'm a big fan of weak coupling, so tying these two dialogs together like this would not be my first choice. I would opt for a "data transfer" or "liaison" class instead. This is a one-instance class where you would put all of your shared data.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
By the way, you can just explain this :
CFileDialog *pOpenDlg=new CFileDialog(FALSE,".txt",NULL,OFN_OVERWRITEPROMPT,"Text Files (*.txt)|*.txt|All Files(*.*)|*.*||");
if you want some more charity from our heavenly father?? :)PLEASE! :(
Try and put this code in a button click and see what happens. then you will understand why is this code required.
Every new day is another chance to change your life.