积极答复者
关于vc6下EditBox在win2k下无法输入字符的问题

问题
-
本人在winXP下做了一个格式转换的小程序,用到一个EditBox,对该控件的数值类型,新建了一个类对其进行了重新定义:
// NumEdit.cpp : implementation file
//#include "stdafx.h"
#include "TYSH_DC.h"
#include "NumEdit.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CNumEditCNumEdit::CNumEdit()
{
}CNumEdit::~CNumEdit()
{
}
BEGIN_MESSAGE_MAP(CNumEdit, CEdit)
//{{AFX_MSG_MAP(CNumEdit)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CNumEdit message handlersBOOL CNumEdit::PreTranslateMessage(MSG* pMsg)
{
//截获键盘消息,并限制输入的字符与长度
if(pMsg->message==WM_KEYDOWN)
{
int nKey=(int)pMsg->wParam;
if((nKey>='0'&&nKey<='9')|| //主键盘0-9
(nKey>=96&&nKey<=105)|| //小键盘0-9
(nKey==8)||(nKey==46)|| //退格符|删除
(nKey==VK_RIGHT)||(nKey==VK_LEFT)) //右|左
{
int s,e;
s=0;e=0;
//获得当前空间上光标的选中区域
this->GetSel(s,e);
if(e==8)
{
if((nKey!=VK_LEFT)&&(nKey!=8))
return TRUE;
}}
else
{
return TRUE;
}}
return CEdit::PreTranslateMessage(pMsg);
}
在winxp下运行正常,但在一台win2k机子下运行取无法输入字符,而另一台win2k的server版下运行却正常.不知什么原因,请各位高手指教,谢谢!
答案
-
EditBox是有只能输入数字的风格。
- ES_NUMBER
- Allows only digits to be entered into the edit control. Note that, even with this set, it is still possible to paste non-digits into the edit control.
To change this style after the control has been created, use SetWindowLong.
你不必自己编写。
0xBAADF00D- 已标记为答案 Nancy Shao 2010年3月16日 9:48
全部回复
-
EditBox是有只能输入数字的风格。
- ES_NUMBER
- Allows only digits to be entered into the edit control. Note that, even with this set, it is still possible to paste non-digits into the edit control.
To change this style after the control has been created, use SetWindowLong.
你不必自己编写。
0xBAADF00D- 已标记为答案 Nancy Shao 2010年3月16日 9:48