Click to See Complete Forum and Search --> : a strange problem about CSpinButtonCtrl?


liben
August 8th, 1999, 01:13 AM
I wrote a dialog based app with Visual C++ 6.0.In CAboutDlg class, I use Resource Editor to add a CSpinButtonCtrl control.It's ID is ID_SPIN1.In ClassWizard,I attach a Member Variable to it.The variable's type is CSpinButtonCtrl and it's name is m_spin1.I wrote the code:

CAboutDlg aboutdlg;
aboutdlg.m_spin1.SetRange(1,31);//cause assertion failure
aboutdlg.DoModal();



I can complied it with no error.But when I run these code,any member function of CSpinButtonCtrl will cause assertion failure.Perhaps put these code in aboutdlg.OnInitDialog member function will not cause error,but I can't.Because I must set and get the CSpinButtonCtrl control's data in a generic class.Please help me!

Martin Speiser
August 8th, 1999, 04:57 AM
Hi,

SetRange requires that the window of CSpinButtonCtrl is actually created, and the member control variable is connected with it. This is done after DoDataExchange is called. So you can't call SetRange before the base implementation of OnInitDialog is called, which will call DoDataExchange.

The only solution is to set a member variable of your dialog class, and then call SetRange in your implementation of OnInitDialog.

Martin