我想在对话框中写子类型化edit使它只接收数字,但总是不对
editclass.h:
class myedit:public CEdit
{
protected:
 afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
DECLARE_MESSAGE_MAP()};
editclass.cpp:
#include "stdafx.h"
#include "editclass.h"BEGIN_MESSAGE_MAP(myedit,CEdit)
   
 ON_WM_CHAR()
  
END_MESSAGE_MAP()void myedit::OnChar(UINT nChar,UINT nRepCnt,UINT nFlags)
{
MessageBox("wushuang");}
我也在对话框的头文件中加入了myedit my_edit;
编译没问题,但是链接时出错.就是 DECLARE_MESSAGE_MAP()的问题,去掉就不会出错了;
去掉后
我在BOOL CTest123Dlg::OnInitDialog()中加入了my_edit1->SubclassDlgItem(IDC_EDIT1,this);
运行时在编辑框中键入键时还是没有调用myedit::onchar()
还有我找不到edit里面有onchar这个消息啊

解决方案 »

  1.   

    DECLARE_MESSAGE_MAP()去掉了,就没有挂接消息处理函数了,当然不会执行!
      

  2.   

    参考定义:
    class CEditBase : public CEdit
    {
    public:
    CEditBase () 
    {
    m_bEmpty = true;
    }
    virtual ~CEditBase () {} protected:
    virtual BOOL ProcessChar (UINT nChar)
    {
    ASSERT (FALSE); // Must be provided by derived class
    return (FALSE);
    } bool m_bEmpty; protected:
    afx_msg void OnChar (UINT nChar, UINT nRepCnt, UINT nFlags);
    afx_msg long OnPaste (WPARAM wNotUsed, LPARAM lNotUsed); DECLARE_MESSAGE_MAP ();
    };
      

  3.   

    在对应的实现文件(cpp文件)中:
    BEGIN_MESSAGE_MAP (CEditBase, CEdit)
    ON_WM_CHAR ()
    ON_MESSAGE (WM_PASTE, OnPaste)
    END_MESSAGE_MAP ()
      

  4.   

    这么直接在内向导中找不到ON_WM_CHA呢,是包含在EN_CHANGE中吗