●怎样实现:在EDIT框里限定某些字符的输入?(比如不许空格输入)● 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用子类化窗口,在里面处理OnChar(), 可以重载PretranslateMessage( MSG *pMsg )if( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN ){ CWnd *pWnd = GetFocus(); if( pWnd->GetDlgCtrlID() == IDC_EDIT1 ) return TRUE;}return CDialog::PretranslateMessage( pMsg );屏蔽回车 怎么重载OnChar?怎么操作?能给出代码吗?拜托了! 一个十六进制的edit控件只接受0-9,a-eedithex.h#if !defined(AFX_EDITHEX_H__C111B461_897C_11D4_A32C_D58152026D09__INCLUDED_)#define AFX_EDITHEX_H__C111B461_897C_11D4_A32C_D58152026D09__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// EditHex.h : header file///////////////////////////////////////////////////////////////////////////////// CEditHex window#define EN_ESCUP WM_USER+0x0903#define EN_ENTERUP WM_USER+0x904class CEditHex : public CEdit{// Constructionpublic: CEditHex();// Attributespublic:// Operationspublic:// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CEditHex) protected: virtual void PreSubclassWindow(); //}}AFX_VIRTUAL// Implementationpublic: virtual ~CEditHex(); // Generated message map functionsprotected: //{{AFX_MSG(CEditHex) afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnSetFocus(CWnd* pOldWnd); afx_msg void OnKillFocus(CWnd* pNewWnd); //}}AFX_MSG DECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_EDITHEX_H__C111B461_897C_11D4_A32C_D58152026D09__INCLUDED_)edithex.cpp// EditHex.cpp : implementation file//#include "stdafx.h"#include "EditHex.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CEditHexCEditHex::CEditHex(){}CEditHex::~CEditHex(){}BEGIN_MESSAGE_MAP(CEditHex, CEdit) //{{AFX_MSG_MAP(CEditHex) ON_WM_CHAR() ON_WM_KEYUP() ON_WM_LBUTTONDOWN() ON_WM_SETFOCUS() ON_WM_KILLFOCUS() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CEditHex message handlersvoid CEditHex::PreSubclassWindow() { // TODO: Add your specialized code here and/or call the base class CEdit::PreSubclassWindow(); SetLimitText(8);}void CEditHex::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if(nChar>='a'&&nChar<='f') { nChar=nChar+'A'-'a'; SendMessage(WM_CHAR,nChar,nFlags); return; } if(('0'<=nChar&&nChar<='9')||('A'<=nChar&&nChar<='F')||nChar==VK_BACK) CEdit::OnChar(nChar,nRepCnt,nFlags);}void CEditHex::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { if(nChar==0x0d) GetParent()->PostMessage (WM_COMMAND,(WPARAM)(EN_ENTERUP<<16|GetDlgCtrlID()),(LPARAM)m_hWnd); CEdit::OnKeyUp(nChar, nRepCnt, nFlags);}void CEditHex::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CEdit::OnLButtonDown(nFlags, point);}void CEditHex::OnSetFocus(CWnd* pOldWnd) { CEdit::OnSetFocus(pOldWnd); ShowCaret(); // TODO: Add your message handler code here }void CEditHex::OnKillFocus(CWnd* pNewWnd) { CEdit::OnKillFocus(pNewWnd); // TODO: Add your message handler code here } 跪求解脱,MVC中的M让人吐血... vc制作简单播放器问题? 恳求:VC动态运行ActiveX的例子 设置断点时,怎么每都到 disassembly窗口. CListCtrl控件怎么设置其宽度和高度? 如何改变ToolBar整个工具条的颜色 为什么程序连接的时候有两处错误? 求助:如何在MFC的对话框界面嵌入表格 求 X 的 n 次方根用什么函数? 谁有Visual assist的密码? SDI与MDI的区别 请oldworm(oldworm) 和大家进来谈谈勾函数的方法
PretranslateMessage( MSG *pMsg )if( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
{
CWnd *pWnd = GetFocus();
if( pWnd->GetDlgCtrlID() == IDC_EDIT1 )
return TRUE;
}
return CDialog::PretranslateMessage( pMsg );屏蔽回车
能给出代码吗?拜托了!
只接受0-9,a-eedithex.h#if !defined(AFX_EDITHEX_H__C111B461_897C_11D4_A32C_D58152026D09__INCLUDED_)
#define AFX_EDITHEX_H__C111B461_897C_11D4_A32C_D58152026D09__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// EditHex.h : header file
///////////////////////////////////////////////////////////////////////////////
// CEditHex window
#define EN_ESCUP WM_USER+0x0903
#define EN_ENTERUP WM_USER+0x904class CEditHex : public CEdit
{
// Construction
public:
CEditHex();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEditHex)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CEditHex(); // Generated message map functions
protected:
//{{AFX_MSG(CEditHex)
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnKillFocus(CWnd* pNewWnd);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_EDITHEX_H__C111B461_897C_11D4_A32C_D58152026D09__INCLUDED_)edithex.cpp// EditHex.cpp : implementation file
//#include "stdafx.h"
#include "EditHex.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CEditHexCEditHex::CEditHex()
{
}CEditHex::~CEditHex()
{
}
BEGIN_MESSAGE_MAP(CEditHex, CEdit)
//{{AFX_MSG_MAP(CEditHex)
ON_WM_CHAR()
ON_WM_KEYUP()
ON_WM_LBUTTONDOWN()
ON_WM_SETFOCUS()
ON_WM_KILLFOCUS()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CEditHex message handlersvoid CEditHex::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CEdit::PreSubclassWindow();
SetLimitText(8);
}void CEditHex::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar>='a'&&nChar<='f')
{
nChar=nChar+'A'-'a';
SendMessage(WM_CHAR,nChar,nFlags);
return;
}
if(('0'<=nChar&&nChar<='9')||('A'<=nChar&&nChar<='F')||nChar==VK_BACK)
CEdit::OnChar(nChar,nRepCnt,nFlags);
}void CEditHex::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{ if(nChar==0x0d)
GetParent()->PostMessage (WM_COMMAND,(WPARAM)(EN_ENTERUP<<16|GetDlgCtrlID()),(LPARAM)m_hWnd);
CEdit::OnKeyUp(nChar, nRepCnt, nFlags);
}void CEditHex::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CEdit::OnLButtonDown(nFlags, point);
}void CEditHex::OnSetFocus(CWnd* pOldWnd)
{
CEdit::OnSetFocus(pOldWnd);
ShowCaret();
// TODO: Add your message handler code here
}void CEditHex::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
}