MFC文本框限制输入数字,输入其他字符时,如何屏蔽错误信息? 我在MFC中,加入了一个edit框,把它的NUMBER属性设置为true,限制只能输入数字然后我在调试时,输入其他字符,比如字母什么的,它会弹出一个错误气球“不能接受的字符”,我不想要这个东西,请问怎么屏蔽??或者改写也可以。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class CEdit* m_edit = (CEdit*)GetDlgItem(IDC_EDIT1); if((GetFocus()==m_edit) && (pMsg->message == WM_CHAR)) { if(pMsg->wParam>'9' || pMsg->wParam<'0') { return 0; } } return CDialog::PreTranslateMessage(pMsg);} 这么改的话,是不是不需要设置edit的属性为NUMBER了? 把NUMBER属性去掉,那么字母什么的,就能输入进去了,但是我只要输入数字。 取消对Number的设置。再在PreTranslateMessage()中进行处理,或者处理的控件的WM_KEYDOWN或WM_KEYUP消息。 我知道了,把edit框的number去掉,然后你那个返回值错误了,返回的应该是true!这样字母就不会输入进去,也不会有消息。但是新的问题又出现了,删除不能用了! 你去掉NUMBER的属性,然后用上面那段代码,可以输入非数字的字符吗? BOOL CMyEdit::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message == WM_CHAR) { if('.' == pMsg->wParam) { if(!m_isDotExist) { m_isDotExist = TRUE; return CEdit::PreTranslateMessage(pMsg); } else { pMsg->wParam = 0; return FALSE; } } if((pMsg->wParam < '0' || pMsg->wParam >'9')) { pMsg->wParam = 0; return FALSE; } } return CEdit::PreTranslateMessage(pMsg);} 小波变换的程序 多线程中使用Skin? vc++怎么判断日期格式正确? CString类型与LPTSTR类型之间如何转换? 如何建立个象输入法那样的窗口 最近想自己写个项目玩玩。谁给个有意思点的题目?谢谢。 知道计算机名和IP地址,怎么得到该用户所在局域网中的工作组名? 找兼职(只限北京) 有谁知道在vc创建的dll中如何使用string资源? !!!!!!!!!!!打不开数据库??????????????????? 急需求一个用VC++做前台,SQL数据库做后台的管理系统 Vc cmd telnet 初学VC 求有这方面编程经历的发套源码给我做学习用
{
// TODO: Add your specialized code here and/or call the base class
CEdit* m_edit = (CEdit*)GetDlgItem(IDC_EDIT1);
if((GetFocus()==m_edit) && (pMsg->message == WM_CHAR))
{
if(pMsg->wParam>'9' || pMsg->wParam<'0')
{
return 0; }
}
return CDialog::PreTranslateMessage(pMsg);
}
把NUMBER属性去掉,那么字母什么的,就能输入进去了,但是我只要输入数字。
再在PreTranslateMessage()中进行处理,或者处理的控件的WM_KEYDOWN或WM_KEYUP消息。
我知道了,把edit框的number去掉,然后你那个返回值错误了,返回的应该是true!这样字母就不会输入进去,也不会有消息。但是新的问题又出现了,删除不能用了!
你去掉NUMBER的属性,然后用上面那段代码,可以输入非数字的字符吗?
BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_CHAR)
{
if('.' == pMsg->wParam)
{
if(!m_isDotExist)
{
m_isDotExist = TRUE;
return CEdit::PreTranslateMessage(pMsg);
}
else
{
pMsg->wParam = 0;
return FALSE;
}
} if((pMsg->wParam < '0' || pMsg->wParam >'9'))
{
pMsg->wParam = 0;
return FALSE;
}
} return CEdit::PreTranslateMessage(pMsg);
}