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. Dialog Box DDX problem

Dialog Box DDX problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiondebugginghelp
7 Posts 3 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.
  • K Offline
    K Offline
    kitty5
    wrote on last edited by
    #1

    Background: I first created an MDI MFC application called test. I then created a dialog named: IDD_MANUAL_CDIN. This does simple data exchange: User inputs a string in edit box1 (i.e. hello). User clicks on "SEND" button. User should see in edit box2 "I typed: hello". I then created a class for that dialog which is implemented in manual.cpp: #include "stdafx.h" #include "test.h" #include "manual.h" // manual dialog IMPLEMENT_DYNAMIC(manual, CDialog) manual::manual(CWnd* pParent /*=NULL*/) : CDialog(manual::IDD, pParent) , m_nIn(_T("init")) , m_nSent(_T("I sent ")) {} void manual::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_IN, m_nIn); DDX_Text(pDX, IDC_SENT, m_nSent); } BEGIN_MESSAGE_MAP(manual, CDialog) ON_BN_CLICKED(IDC_BUTTON_SEND, &manual::OnButtonSend) END_MESSAGE_MAP() // App command to run the dialog void manual::OnManual() { manual manualDlg; manualDlg.DoModal(); } // manual message handlers void manual::OnButtonSend() { // TODO: Add your control notification handler code here AfxMessageBox(tempSend); //DEBUG AfxMessageBox(m_nIn); //DEBUG m_nSent += m_nIn; } and manual.h: class manual : public CDialog { DECLARE_DYNAMIC(manual) public: manual(CWnd* pParent = NULL); // standard constructor virtual ~manual(); afx_msg void OnManual(); // Dialog Data enum { IDD = IDD_MANUAL_CDIN }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support DECLARE_MESSAGE_MAP() public: CString m_nIn; CString m_nSent; afx_msg void OnButtonSend(); }; I then changed the toolbar created by the MFC App wizard so that when you click one button it will open a dialog that corresponds to that button. All this code is in the test.cpp file: I do: #include "manual.h" BEGIN_MESSAGE_MAP(CSpaceCubeDataRxApp, CWinApp) ON_COMMAND(ID_MCD_INPUT, &manual::OnManual) ON_COMMAND(ID_APP_ABOUT, &CtestApp::OnAppAbout) // Standard file based document commands ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen) END_MESSAGE_MAP() Question: After compiling I go to type in the string "hello" and click send and nothing pops up in edit box2. I know the "SEND" button function works b/c of the DEBUG AfxMessageBox the I put in it. Nothing is assigned to the variable m_nIn. The data exchange isn't working. What am I missing? Kitty5

    M D 2 Replies Last reply
    0
    • K kitty5

      Background: I first created an MDI MFC application called test. I then created a dialog named: IDD_MANUAL_CDIN. This does simple data exchange: User inputs a string in edit box1 (i.e. hello). User clicks on "SEND" button. User should see in edit box2 "I typed: hello". I then created a class for that dialog which is implemented in manual.cpp: #include "stdafx.h" #include "test.h" #include "manual.h" // manual dialog IMPLEMENT_DYNAMIC(manual, CDialog) manual::manual(CWnd* pParent /*=NULL*/) : CDialog(manual::IDD, pParent) , m_nIn(_T("init")) , m_nSent(_T("I sent ")) {} void manual::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_IN, m_nIn); DDX_Text(pDX, IDC_SENT, m_nSent); } BEGIN_MESSAGE_MAP(manual, CDialog) ON_BN_CLICKED(IDC_BUTTON_SEND, &manual::OnButtonSend) END_MESSAGE_MAP() // App command to run the dialog void manual::OnManual() { manual manualDlg; manualDlg.DoModal(); } // manual message handlers void manual::OnButtonSend() { // TODO: Add your control notification handler code here AfxMessageBox(tempSend); //DEBUG AfxMessageBox(m_nIn); //DEBUG m_nSent += m_nIn; } and manual.h: class manual : public CDialog { DECLARE_DYNAMIC(manual) public: manual(CWnd* pParent = NULL); // standard constructor virtual ~manual(); afx_msg void OnManual(); // Dialog Data enum { IDD = IDD_MANUAL_CDIN }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support DECLARE_MESSAGE_MAP() public: CString m_nIn; CString m_nSent; afx_msg void OnButtonSend(); }; I then changed the toolbar created by the MFC App wizard so that when you click one button it will open a dialog that corresponds to that button. All this code is in the test.cpp file: I do: #include "manual.h" BEGIN_MESSAGE_MAP(CSpaceCubeDataRxApp, CWinApp) ON_COMMAND(ID_MCD_INPUT, &manual::OnManual) ON_COMMAND(ID_APP_ABOUT, &CtestApp::OnAppAbout) // Standard file based document commands ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen) END_MESSAGE_MAP() Question: After compiling I go to type in the string "hello" and click send and nothing pops up in edit box2. I know the "SEND" button function works b/c of the DEBUG AfxMessageBox the I put in it. Nothing is assigned to the variable m_nIn. The data exchange isn't working. What am I missing? Kitty5

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      DDX doesn't happen automagically, you need to call UpdateData() to transfer the data between the controls and variables. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      K 2 Replies Last reply
      0
      • M Michael Dunn

        DDX doesn't happen automagically, you need to call UpdateData() to transfer the data between the controls and variables. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        K Offline
        K Offline
        kitty5
        wrote on last edited by
        #3

        DUH!:doh: I knew it was something simple... Kitty5

        1 Reply Last reply
        0
        • K kitty5

          Background: I first created an MDI MFC application called test. I then created a dialog named: IDD_MANUAL_CDIN. This does simple data exchange: User inputs a string in edit box1 (i.e. hello). User clicks on "SEND" button. User should see in edit box2 "I typed: hello". I then created a class for that dialog which is implemented in manual.cpp: #include "stdafx.h" #include "test.h" #include "manual.h" // manual dialog IMPLEMENT_DYNAMIC(manual, CDialog) manual::manual(CWnd* pParent /*=NULL*/) : CDialog(manual::IDD, pParent) , m_nIn(_T("init")) , m_nSent(_T("I sent ")) {} void manual::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_IN, m_nIn); DDX_Text(pDX, IDC_SENT, m_nSent); } BEGIN_MESSAGE_MAP(manual, CDialog) ON_BN_CLICKED(IDC_BUTTON_SEND, &manual::OnButtonSend) END_MESSAGE_MAP() // App command to run the dialog void manual::OnManual() { manual manualDlg; manualDlg.DoModal(); } // manual message handlers void manual::OnButtonSend() { // TODO: Add your control notification handler code here AfxMessageBox(tempSend); //DEBUG AfxMessageBox(m_nIn); //DEBUG m_nSent += m_nIn; } and manual.h: class manual : public CDialog { DECLARE_DYNAMIC(manual) public: manual(CWnd* pParent = NULL); // standard constructor virtual ~manual(); afx_msg void OnManual(); // Dialog Data enum { IDD = IDD_MANUAL_CDIN }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support DECLARE_MESSAGE_MAP() public: CString m_nIn; CString m_nSent; afx_msg void OnButtonSend(); }; I then changed the toolbar created by the MFC App wizard so that when you click one button it will open a dialog that corresponds to that button. All this code is in the test.cpp file: I do: #include "manual.h" BEGIN_MESSAGE_MAP(CSpaceCubeDataRxApp, CWinApp) ON_COMMAND(ID_MCD_INPUT, &manual::OnManual) ON_COMMAND(ID_APP_ABOUT, &CtestApp::OnAppAbout) // Standard file based document commands ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen) END_MESSAGE_MAP() Question: After compiling I go to type in the string "hello" and click send and nothing pops up in edit box2. I know the "SEND" button function works b/c of the DEBUG AfxMessageBox the I put in it. Nothing is assigned to the variable m_nIn. The data exchange isn't working. What am I missing? Kitty5

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

          kitty5 wrote:

          void manual::OnManual() { manual manualDlg; manualDlg.DoModal(); }

          Is this right? I've never seen a dialog's method bring up another instance of itself. Why do you not have two CEdit member variables in manual, one for each of the edit controls?


          "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

          "Judge not by the eye but by the heart." - Native American Proverb

          K 1 Reply Last reply
          0
          • D David Crow

            kitty5 wrote:

            void manual::OnManual() { manual manualDlg; manualDlg.DoModal(); }

            Is this right? I've never seen a dialog's method bring up another instance of itself. Why do you not have two CEdit member variables in manual, one for each of the edit controls?


            "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

            "Judge not by the eye but by the heart." - Native American Proverb

            K Offline
            K Offline
            kitty5
            wrote on last edited by
            #5

            DavidCrow wrote:

            kitty5 wrote: void manual::OnManual() { manual manualDlg; manualDlg.DoModal(); } Is this right? I've never seen a dialog's method bring up another instance of itself.

            I copied exactly what the MFC App wizard did for the AboutBox that it provides.

            DavidCrow wrote:

            Why do you not have two CEdit member variables in manual, one for each of the edit controls?

            Yes, one for each edit control... Actually, I changed the "Variable Type" to CString and the "Category" to Value (This was all done when you right click on the edit box and click on "Add Variable". Did I do something wrong? Kitty5

            D 1 Reply Last reply
            0
            • K kitty5

              DavidCrow wrote:

              kitty5 wrote: void manual::OnManual() { manual manualDlg; manualDlg.DoModal(); } Is this right? I've never seen a dialog's method bring up another instance of itself.

              I copied exactly what the MFC App wizard did for the AboutBox that it provides.

              DavidCrow wrote:

              Why do you not have two CEdit member variables in manual, one for each of the edit controls?

              Yes, one for each edit control... Actually, I changed the "Variable Type" to CString and the "Category" to Value (This was all done when you right click on the edit box and click on "Add Variable". Did I do something wrong? Kitty5

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

              kitty5 wrote:

              I copied exactly what the MFC App wizard did for the AboutBox that it provides.

              Unlikely. That code would most likely resemble:

              void CMyDialog::OnManual()
              {
              CAboutDlg about;
              about.DoModal();
              }

              Note how the two dialog objects are different.

              kitty5 wrote:

              Yes, one for each edit control... Actually, I changed the "Variable Type" to CString and the "Category" to Value (This was all done when you right click on the edit box and click on "Add Variable". Did I do something wrong?

              I personally do not use CString for edit controls. That's what CEdit was designed for. Use its SetWindowText() method, rather than UpdateData(), and you'll have far less problems.


              "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

              "Judge not by the eye but by the heart." - Native American Proverb

              1 Reply Last reply
              0
              • M Michael Dunn

                DDX doesn't happen automagically, you need to call UpdateData() to transfer the data between the controls and variables. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                K Offline
                K Offline
                kitty5
                wrote on last edited by
                #7

                :-D Ok, I've figured out how to get the dialog boxes to exchange data. Now I'm trying to figure out how when you have one dialog box open how you can open another one while the 1st box is still open and functioning. Right now when I have a dialog box open I can only work in the one box and can't click on anything outside it (i.e. clicking on the toolbar to open another dialog box or getting the about box to come up isn't working...) I guess I'm looking for making these dialog boxes work like child forms in an MDI MFC App. Thanks, Kitty5 -- modified at 9:17 Friday 21st July, 2006

                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