我添加了一个类CHexEditclass CHexEdit : public CEdit
{}然后为该类添加了WM_CHAR消息处理函数void CHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
NKDbgPrintfW(TEXT("\r\n++CHexEdit::OnChar().\r\n")); CString Holder = TEXT("0987654321abcdefABCDEF");  if((nChar != VK_BACK) && (Holder.Find(nChar) == -1))

return; 
}  CEdit::OnChar(nChar, nRepCnt, nFlags);
}然后给界面的编辑框加了个CEdit类型的变量,之后把CEdit类型修改为自己的CHexEdit。但调试的时候发现,当我输入. / ;等字符时,可以进入到OnChar函数,但当我输入3,4,a,b等字符时,却没有进入到
OnChar函数。当我输入中文汉字的时候,也没有进入到OnChar函数。请教一下,这是为什么,我该如何做。下面的代码也同样不行,因为输入汉字或者字母数字的时候,根本不进入OnChar函数。奇怪的是,当我输入\,分号等字符的时候却可以进入OnChar。
void CHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
NKDbgPrintfW(TEXT("\r\n++CHexEdit::OnChar().\r\n")); if(IsDBCSLeadByte(nChar)) 

return; 
}  CEdit::OnChar(nChar, nRepCnt, nFlags);
}另外我的MFC对话框程序,是Unicode编码的,系统是WinCE。谢谢大家。

解决方案 »

  1.   

    void CEasyPadView::OnSetFocus(CWnd* pOldWnd) 
    {
    CEditView::OnSetFocus(pOldWnd);
    // TODO: Add your message handler code here
    // no chinese input hanzi !
    ImmAssociateContext(this->m_hWnd, NULL);
    }
      

  2.   

    你的CHexEdit类添加WindowProc虚函数,在里面处理WM_IME_CHAR消息
      

  3.   


    LRESULT CHexEdit::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
    {
    if(WM_IME_CHAR == message)
    {
    AfxMessageBox(_T("中文"));
    }
    return CEdit::WindowProc(message, wParam, lParam);
    }
      

  4.   

    http://blog.csdn.net/shihaojie1219/article/details/5775017
      

  5.   


    不知道是不是wince下不支持WM_IME_CHAR消息,这个MessageBox没有弹出来。
      

  6.   

    非常奇怪的是为什么输入标点,斜杠等字符的时候,能进入到OnChar函数。但输入abcd字母或者数字或者中文就进入不到OnChar函数。
      

  7.   

    我把WindowProc的所有消息都打印到log里面了。比如我输入个字母j的时候,会有如下消息。里面没有WM_CHAR(0x0102),也没有WM_IME_CHAR(0x0286)++CHexEdit::WindowProc(). message = 0x0087.
    ++CHexEdit::WindowProc(). message = 0x0100.
    ++CHexEdit::WindowProc(). message = 0x010f.
    ++CHexEdit::WindowProc(). message = 0x0087.
    ++CHexEdit::WindowProc(). message = 0x0101.不过我输入标点,比如;号的时候。消息如下:
    看以看到WM_CHAR(0x0102)消息有了,程序也进入到OnChar里面了。
    ++CHexEdit::WindowProc(). message = 0x0087.
    ++CHexEdit::WindowProc(). message = 0x0100.
    ++CHexEdit::WindowProc(). message = 0x0087.
    ++CHexEdit::WindowProc(). message = 0x0102.
    ++CHexEdit::OnChar().
    ++CHexEdit::WindowProc(). message = 0x0087.
    ++CHexEdit::WindowProc(). message = 0x0101.
    ++CHexEdit::WindowProc(). message = 0x000f.
      

  8.   


    void CEditCheck::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default
    //if ( !IsCharAlpha( nChar) && !::isdigit( nChar) )
    if( nChar >= 128 )
    {
    return;
    }

    CEdit::OnChar(nChar, nRepCnt, nFlags);
    }
      

  9.   

    void GetInputStringFromString( CString& strText)
    { CString strDest = "";
    char ch = 0;
    int nLen = strText.GetLength();
    for( int i = 0 ; i < nLen; ++i )
    {
    if( strText.GetAt( i ) >=128 || strText.GetAt( i ) < 0 )
    {
    strText = "";
    AfxMessageBox(L"输入不能含有中文汉字!");
    return;
    }
    }        //根据需要还可以判断其他字符的合法性....... strText = strDest ;
    }//处理复制进行粘贴,防止粘贴中文
    LRESULT CEditCheck::OnPaste( WPARAM wParam, LPARAM lParam)
    {
    CEdit::Default();
    CString strText = "";
    GetWindowText( strText );
    GetInputStringFromString(strText);
    SetWindowText( strText );
    return 0L;
    }
      

  10.   

    lass CEditCheck : public CEdit
    {
    // Construction
    public:
    CEditCheck();// Attributes
    public:// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CEditCheck)

    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CEditCheck(); // Generated message map functions
    protected:
    //{{AFX_MSG(CEditCheck)
    afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
    //}}AFX_MSG
    LRESULT   OnPaste( WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP()
    };
    //Cpp 消息
    BEGIN_MESSAGE_MAP(CEditCheck, CEdit)
    //{{AFX_MSG_MAP(CEditCheck)
    ON_MESSAGE(WM_PASTE,OnPaste)
    ON_WM_CHAR()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()