Dialog Box DDX problem
-
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 -
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? Kitty5DDX 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 -
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 -
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? Kitty5kitty5 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 inmanual
, 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
-
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 inmanual
, 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
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
-
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
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 whatCEdit
was designed for. Use itsSetWindowText()
method, rather thanUpdateData()
, 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
-
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:-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