// RealEdit *********************************************** #include #pragma hdrstop #include #include #ifdef __BORLANDC__ #include #else #include #endif RealEdit::RealEdit(Object *Parent,int Id,double Value,int Decs,long Flags,double Min,double Max) : Edit(Parent,Id) { FLAGS=Flags; MIN=Min; MAX=Max; char temp[20]; sprintf(temp,"%.*g",Decs,Value); SetString(temp); } BOOL RealEdit::CanClose() { char temp[128]=""; int err=0; double Value=GetValue(&err); if (err) strcpy(temp,"Please enter a valid number"); else if ((ValueMAX && (FLAGS & NE_MAX) && !(FLAGS & NE_MIN))) sprintf(temp,"Please enter a number below %lf",MAX); else if ((( ValueMAX ) && (FLAGS & NE_MINMAX))) sprintf(temp,"Please enter a number between %lf and %lf",MIN,MAX); else if (Value<0 && (FLAGS & NE_POS)) strcpy(temp,"Please enter a positive number"); else if (Value>0 && (FLAGS & NE_NEG)) strcpy(temp,"Please enter a negative number"); else if (Value==0 && (FLAGS & NE_NONZERO)) strcpy(temp,"Please enter a non-zero number"); if (*temp) { // handle needs to be that of window not control MessageBox(ParentHWnd,temp,"Error",MB_OK | MB_ICONEXCLAMATION); SendMessage(hWnd, EM_SETSEL,0,MAXINT); SetFocus(hWnd); return FALSE; } return TRUE; } double RealEdit::GetValue(BOOL *err) { double Value; char *temp=GetString(); if (sscanf(temp,"%lf",&Value)<=0 && err) *err=1; delete[] temp; return Value; }