Re: Simple DDX_Text with edit box and spin button falls over
Hi Mike,
You could set a breakpoint in your OnInitDialog() function and your change
handler and see if the change handler is getting called first (not sure why
it would). You need to make sure not to access any of the controls until
the base class call for the OnInitDialog() function is called (usually put
at top of the function). Anyway, a debug (or perhaps TRACE message) could
reveal the order that things are happening.
Tom
"Mike Silva" <snarflemike@yahoo.com> wrote in message
news:116255a8-e5bd-4dea-8b70-864a5e86aacf@d77g2000hsb.googlegroups.com...
I've run across something I've never encountered before, though I've
used spin buttons many times in the past. I've reduced it to a bare
minimum program as follows.
-Create an MFC dialog app
-Add two edit boxes and two spin buttons, one for each box (in the
correct order)
-Add integer variables to each edit box
-Set the spin buttons to autobuddy the edit boxes and to setbuddyint
-Create OnChangeEdit() methods for each edit box
-Inside the methods, call UpdateData( false ) to read the edit box
integers
On the generated call to DDX_Text for the second edit box
( DDX_Text(pDX, IDC_EDIT2, m_edit2); ) the method HWND
CDataExchange::PrepareCtrl(int nIDC) in dlgdata.cpp fails at the
ASSERTS( FALSE ) point - the associated trace message is "Error: no
data exchange control with ID 1001". Most assuredly the ID 1001 does
exist.
This fails on both Visa Basic and XP.
Here are some code snippets:
from my resource.h
#define IDC_EDIT1 1000
#define IDC_EDIT2 1001
....
#define IDC_SPIN1 1007
#define IDC_SPIN2 1008
from my .rc
BEGIN
DEFPUSHBUTTON "OK",IDOK,263,7,50,16
PUSHBUTTON "Cancel",IDCANCEL,263,25,50,16
EDITTEXT IDC_EDIT1,138,78,48,14,ES_AUTOHSCROLL
CONTROL "",IDC_SPIN1,"msctls_updown32",UDS_SETBUDDYINT |
UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,186,78,10,14
EDITTEXT IDC_EDIT2,138,102,48,14,ES_AUTOHSCROLL
CONTROL "",IDC_SPIN2,"msctls_updown32",UDS_SETBUDDYINT |
UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,186,102,11,14
from my .h
int m_edit1;
int m_edit2;
....
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
private:
afx_msg void OnEnChangeEdit1();
afx_msg void OnEnChangeEdit2();
from my .cpp
void CDlgTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_edit1);
DDX_Text(pDX, IDC_EDIT2, m_edit2);
}
BEGIN_MESSAGE_MAP(CDlgTestDlg, CDialog)
....
//}}AFX_MSG_MAP
ON_EN_CHANGE(IDC_EDIT1, &CDlgTestDlg::OnEnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, &CDlgTestDlg::OnEnChangeEdit2)
END_MESSAGE_MAP()
....
void CDlgTestDlg::OnEnChangeEdit1() // same code for Edit2
{
UpdateData( true );
....
}
--end code snippets--
If I remove (just comment out) the _first_ spin control in the .rc
file, the program doesn't fail - even though when it fails, it fails
not at the first edit box but at the second one! And if I remove the
second edit box and spin button alltogether, everything works fine!
I'm hoping somebody can figure out what's wrong here, since I'm dead
in the water right now. Many thanks!
Mike