如何在MFC的编辑框中输入负整数值?
我尝试使用Cstring,然后使用_aoti()
将其更改为整数答案 0 :(得分:0)
感谢您的帮助。我找到了一种在编辑框中输入负数的方法。 这是以下代码
//add a macro
#define INVALID_INT_MSG_EX L"Enter an integer between %d and %d."
//declare a global variable
int flag_for_negative_numbers = 0
void CTouchPanelModule::OnEnChangeTpTempValue()
{
UpdateData(true);
if (editBoxVariable_value == _T('-') && (flag_for_negative_numbers == 0))
{
flag_for_negative_numbers = 1;
}
else
{
int tempValueTouchPanel_value = _wtoi(editBoxVariable_value);
ValidateEditCtrl(ID_of_the_edit_box,
editBoxVariable_value,
MIN_value,
MAX_value, default_value);
}
}
//Below is the defination of ValidateEditCtrl() function
bool CustomDialogEx::ValidateEditCtrl(int CtrlId, int& valueToCheck, int minValue, int maxValue, CString defaultValue)
{
auto isValid = true;
UpdateData(TRUE);
if (valueToCheck < minValue || valueToCheck > maxValue)
{
CString cString;
cString.Format(INVALID_INT_MSG_EX, minValue, maxValue);
ChangeMessageBoxTitle appTitle(dlgTitle);
AfxMessageBox(cString);
GetDlgItem(CtrlId)->SetWindowText(defaultValue);
isValid = false;
}
return isValid;
}