Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC - how to get an edit box text from another dialog?? (Constructor)

MFC - how to get an edit box text from another dialog?? (Constructor)

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helptutorial
13 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S symeramon

    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... :(

    A Offline
    A Offline
    App_
    wrote on last edited by
    #2

    use DDX_Text An example of DDX_Text usage

    1 Reply Last reply
    0
    • S symeramon

      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... :(

      enhzflepE Offline
      enhzflepE Offline
      enhzflep
      wrote on last edited by
      #3

      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;
      
      L 1 Reply Last reply
      0
      • S symeramon

        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... :(

        M Offline
        M Offline
        Madhu Nair 0
        wrote on last edited by
        #4

        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)

        S 1 Reply Last reply
        0
        • S symeramon

          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... :(

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #5

          You could use GetDlgItemText()[^] and its counterpart SetDlgItemText().

          Unrequited desire is character building. OriginalGriff

          S 1 Reply Last reply
          0
          • enhzflepE enhzflep

            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;
            
            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            See my response for simpler functions.

            Unrequited desire is character building. OriginalGriff

            enhzflepE 1 Reply Last reply
            0
            • M Madhu Nair 0

              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)

              S Offline
              S Offline
              symeramon
              wrote on last edited by
              #7

              From class wizard, maindialog's member variables I added a member variable to the editbox which gets the editbox's value and then as you said, I equalize each variables but than it returns nothing from main dialog ??? :(

              1 Reply Last reply
              0
              • L Lost User

                You could use GetDlgItemText()[^] and its counterpart SetDlgItemText().

                Unrequited desire is character building. OriginalGriff

                S Offline
                S Offline
                symeramon
                wrote on last edited by
                #8

                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... :))

                1 Reply Last reply
                0
                • L Lost User

                  See my response for simpler functions.

                  Unrequited desire is character building. OriginalGriff

                  enhzflepE Offline
                  enhzflepE Offline
                  enhzflep
                  wrote on last edited by
                  #9

                  :facepalm: Of course! Cheers Richard.

                  1 Reply Last reply
                  0
                  • S symeramon

                    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... :(

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #10

                    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

                    S 2 Replies Last reply
                    0
                    • D David Crow

                      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

                      S Offline
                      S Offline
                      symeramon
                      wrote on last edited by
                      #11

                      Thanks for your reply David... I would like to criticise your post if I was more skilled... But seems :cool: to me for now... Maybe not, in the future?? :laugh: Just joking, thanks again...

                      1 Reply Last reply
                      0
                      • D David Crow

                        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

                        S Offline
                        S Offline
                        symeramon
                        wrote on last edited by
                        #12

                        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! :(

                        C 1 Reply Last reply
                        0
                        • S symeramon

                          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! :(

                          C Offline
                          C Offline
                          Chandrasekharan P
                          wrote on last edited by
                          #13

                          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.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups