|
不要勾选“Number”选项,让edit接收所有字符,添加事件PreTranslateMessage(MSG* pMsg),添加如下代码:
BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
static char bFirst = 0;
if((pMsg->message == WM_CHAR) && (pMsg->hwnd == hwnd))
{
CString str;
int i, len;
if((pMsg->wParam < '0') || (pMsg->wParam > '9'))
{
if(pMsg->wParam != VK_BACK)
{
if(pMsg->wParam == 45)//fu hao '-'
{
if(bFirst != 0)
return TRUE;
bFirst++;
if(bFirst > 200)
bFirst = 1;
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
if(str[0] == '-')
return TRUE;
}
else
return TRUE;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
|
|