Numbers as only valid input in edit control
Im having issues with allowing the users only to enter a number in an edit control. I tried using IsDigit(value) but has trouble when the number when negative.
Is there a valid way of allowing the user to only enter numbers but without limiting to positive? I wanted to avoid having a second option they would have to check for negative / positive.
Code:
switch (message)
{
case WM_INITDIALOG:
SetDlgItemInt(hDlg, IDC_XVECTOR, theDoc.hBall.sBallVec.cx, TRUE);
SetDlgItemInt(hDlg, IDC_YVECTOR, theDoc.hBall.sBallVec.cy, TRUE);
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
LONG tempX = GetDlgItemInt(hDlg, IDC_XVECTOR, FALSE, TRUE);
LONG tempY = GetDlgItemInt(hDlg, IDC_YVECTOR, FALSE, TRUE);
if(tempX < -10)
theDoc.hBall.sBallVec.cx = -10;
else if(tempX > 10)
theDoc.hBall.sBallVec.cx = 10;
else
theDoc.hBall.sBallVec.cx = tempX;
if(tempY < -10)
theDoc.hBall.sBallVec.cy = -10;
else if(tempY > 10)
theDoc.hBall.sBallVec.cy = 10;
else
theDoc.hBall.sBallVec.cy = tempY;
EndDialog(hDlg, LOWORD(wParam));
InvalidateRect(hDlg, NULL, TRUE);
return TRUE;
}
else if(LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
thanks