赞
踩
1)添加个C++类 eg. class Dot:public CEdit
2)给这个类添加onChar()消息
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
3)*.cpp中
void Dot::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
}
4)在*Dlg.h加上
----》#include"Dot.h"
----》Dot
5)在*Dlg.cpp加上
-----》DDX_Control(pDX, IDC_EDIT1, m_s);
或者
- BOOL CWeiXinQ::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: 在此添加专用代码和/或调用基类
- //指定对话框只接受数字按键输入,其他符号输入无效
-
- //获取控件窗口指针
- CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_EDIT1_Q_MONEY);
- CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT2_Q_CODE);
- if( (GetFocus() == pEdit1 ||GetFocus() == pEdit2) && (pMsg->message == WM_CHAR) )
- {
- //只允许输入数字和小数点“.”
- if((pMsg->wParam <= '9' && pMsg->wParam >= '0') || pMsg->wParam == '.')
- {
- //金额输入框只允许输入一个小数点
- if(pMsg->wParam == '.')
- {
- CString str;
- int nPos = 0;
- GetDlgItemText(IDC_EDIT1_Q_MONEY, str); // 获取edit中文本
- nPos = str.Find('.'); // 查找.的位置
- if(nPos >= 0)
- {
- return 1;
- }
- }
-
- return 0;
-
- }
- else if(pMsg->wParam == 0x08 || pMsg->wParam == 0x10) //接受Backspace和delete键
- {
- return 0;
- }
- else
- {
- //响应标签页切换的快捷键
- switch(pMsg->wParam)
- {
- case 'q':
- case 'Q':
- case 'w':
- case 'W':
- case 'e':
- case 'E':
- case 'r':
- case 'R':
- case 't':
- case 'T':
- case 'y':
- case 'Y':
- case 'u':
- case 'U':
- case 'i':
- case 'I':
- case 'o':
- case 'O':
- CWnd *pParent = GetParent();
- pParent->SetFocus();
- }
- return 1;
- }
-
- }
-
- return CDialogEx::PreTranslateMessage(pMsg);
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。