如题

解决方案 »

  1.   

    用子类化窗口,在里面处理OnChar(),
      

  2.   

    可以重载
    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 );屏蔽回车
      

  3.   

    怎么重载OnChar?怎么操作?
    能给出代码吗?拜托了!
      

  4.   

    一个十六进制的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
    {
    // 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

    }