I have found a fix !
It seems in my break point testing in DoDataExchange I had put it after the DDX_Text function. It seems that the "Please enter a positive integer." message come from inside the relvant DDX_Text function somewhere.
I was therefore able to fix the problem by intercepting the value coming from CEdit at the top of DoDataExchange with a bit of validation code. The curcial test you need is to check the text in CEdit to see if the user deleted it all, even though it uses numbers. If he did delete it all I set the text and memver variable to a default value.
I also add validation code for my values range.
void CArtConDlg::DoDataExchange(CDataExchange* pDX)
{
CEdit *cEd ;
CString csTxt ;
cEd = (CEdit*)GetDlgItem(IDC_EDIT_DMINTERVAL) ;
cEd->GetWindowText(csTxt) ;
if(csTxt.IsEmpty()) {
m_iDmInterval = MIN_DMINTERVAL ;
csTxt.Format("%d", m_iDmInterval) ;
cEd->SetWindowText((LPCSTR)csTxt) ;
} else if(m_iDmInterval < MIN_DMINTERVAL) {
m_iDmInterval = MIN_DMINTERVAL ;
} else if(m_iDmInterval > MAX_DMINTERVAL) {
m_iDmInterval = MAX_DMINTERVAL ;
}
cEd = (CEdit*)GetDlgItem(IDC_EDIT_ONESHOTHOURS) ;
cEd->GetWindowText(csTxt) ;
if(csTxt.IsEmpty()) {
m_iTmrOneShotHours = MIN_TMRONESHOTHOURS ;
csTxt.Format("%d", m_iTmrOneShotHours) ;
cEd->SetWindowText((LPCSTR)csTxt) ;
} else if(m_iTmrOneShotHours < MIN_TMRONESHOTHOURS) {
m_iTmrOneShotHours = MIN_TMRONESHOTHOURS ;
} else if(m_iTmrOneShotHours > MAX_TMRONESHOTHOURS) {
m_iTmrOneShotHours = MAX_TMRONESHOTHOURS ;
}
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_SPIN_ONESHOTHOURS, m_ctrlSpinOneShotHours);
DDX_Control(pDX, IDC_SPIN_DMINTERVAL, m_ctrlSpinDmInterval);
DDX_Control(pDX, IDC_TIMERONOFF, m_ctrlTimerOn);
DDX_Control(pDX, IDC_LIGHTSENSORDAYNIGHT, m_ctrlLightSensor);
DDX_Control(pDX, IDC_ARTWORK, m_ctrlArtworkOn);
DDX_Control(pDX, IDC_EDITMODELAP, m_ctrlEditModeLap);
DDX_Control(pDX, IDC_COMMSALIVE, m_ctrlCommsAlive);
DDX_Control(pDX, IDC_EDIT_LUMIN, m_ctrlEditLumin);
DDX_Control(pDX, IDC_SLIDER_LUMIN, m_ctrlSliderLumin);
DDX_Control(pDX, IDC_LIST_FADERS, m_ctrlListFaders);
DDX_Text(pDX, IDC_EDIT_FADERUPDATETIME, m_csFaderUpdateTime);
DDX_Text(pDX, IDC_EDIT_TOTAL_AMPS, m_csTotalAmps);
DDX_Text(pDX, IDC_EDIT_TOTAL_AMPSPCT, m_csTotalAmpsPct);
DDX_Radio(pDX, IDC_RADIO_MODEON, m_iTimerMode);
DDX_Check(pDX, IDC_CHECK_TMRONESHOTONEN, m_bTmrOneShotEn);
DDX_Check(pDX, IDC_CHECK_TMRFRI, m_bTmrFri);
DDX_Check(pDX, IDC_CHECK_TMRMON, m_bTmrMon);
DDX_Check(pDX, IDC_CHECK_TMRSAT, m_bTmrSat);
DDX_Check(pDX, IDC_CHECK_TMRSUN, m_bTmrSun);
DDX_Check(pDX, IDC_CHECK_TMRTHU, m_bTmrThu);
DDX_Check(pDX, IDC_CHECK_TMRTUE, m_bTmrTue);
DDX_Check(pDX, IDC_CHECK_TMRWED, m_bTmrWed);
DDX_Text(pDX, IDC_EDIT_ONESHOTENDENDDATETIME, m_csOneShotEndDateTime);
DDX_Radio(pDX, IDC_RADIO_DMCYCLE, m_iDisplayMode);
DDX_Text(pDX, IDC_EDIT_DMINTERVAL, m_iDmInterval);
DDX_Text(pDX, IDC_EDIT_DMFILE, m_csDmFile);
DDV_MaxChars(pDX, m_csDmFile, 32);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START, m_ctTmrStart);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_FINISH, m_ctTmrFinish);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_ONESHOTSTART, m_ctTmrOneShotStart);
DDX_Text(pDX, IDC_EDIT_ONESHOTHOURS, m_iTmrOneShotHours);
DDX_Radio(pDX, IDC_RADIO_DMPERIODMIN, m_iDmIntervalUnits);
DDX_Text(pDX, IDC_EDIT_DMLASTFILE, m_csDmLastFile);
DDX_Text(pDX, IDC_EDIT_DMLASTUPDATE, m_csDmLastFileUpdated);
DDX_Radio(pDX, IDC_RADIO_LSORAUTO, m_iLightSensorOverRide);
DDX_Slider(pDX, IDC_SLIDER_LUMIN, m_iSliderLumin);
DDX_Text(pDX, IDC_EDIT_LUMIN, m_iEditLumin);
DDX_Text(pDX, IDC_EDIT_FILE, m_csEditFile);
}
|