Re: Best Practice of verify a string in Edit control of MFC
1 and 2 can be done with DDX_Text and DDV_MinMaxDouble
delcare a variable in your dialog class of type double (m_MyDouble)
then your DoDataExchange.
void CDialogFocusDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, m_Edit);
DDX_Text(pDC, IDC_EDIT1, m_MyDouble);
DDV_MinMaxDouble(pDC,MyDouble,0,99999999);
}
3. call the edit control's SetLimitText in your OnInitDialog
m_Edit.SetLimitText(8);
If you only want to allow the user to type numbers then you would need to
set the Number property of the edit to true. But that will prevent the user
from typing a decimal point. So you if you want to allow the user to only
type in numbers and decimal points, maybe even a negative sign then you will
need to subclass the edit control.
AliR.
"Morris" <morris@online.nospam> wrote in message
news:FF827A0E-6495-43EC-8B7C-3BC617797F49@microsoft.com...
HI
In a MFC dialog, I have an CEdit control. I need to
1. Verify its value to be a valid float when a button in the dialog is
clicked.
2. Convert the value to a float variable if 1 succeeds
3. Limit the length of the CEdit control to allow only 8 characters.
Your helps are appreciated.
Morris.