我知道了一些处理消息的方法
BEGIN_MESSAGE_MAP(CDecimalEdit, CEdit)
//}}AFX_MSG_MAP
//ON_EN_CHANGE(IDC_EDT_DEC, &CDecimalEdit::OnEnChangeEdit)
ON_CONTROL_REFLECT(EN_CHANGE, &CDecimalEdit::OnEnChangeEdit)
ON_WM_CHAR()
END_MESSAGE_MAP()
这些方法是提前知道是什么消息,如按键啦什么的。但不够灵活,我想要一种通用的,
只要是消息,我就处理,自己判断一下是什么消息,该怎么处理。比如用
LRESULT SendMessage(          HWND hWnd,
    UINT Msg,
    WPARAM wParam,
    LPARAM lParam
);给它发消息,
它收着了,看一下,
if(Msg == WM_CHAR)
{
...
}else if ()
{
...
}
这样怎么写消息映射啊

解决方案 »

  1.   

    不是自定义消息,我就问
    BEGIN_MESSAGE_MAP(CDecimalEdit, CEdit) END_MESSAGE_MAP() 
    里头咋写
      

  2.   

    我怎么傻了,最常用的
    PreTranslateMessage
    都忘了,先试试
      

  3.   

    先自定义一个消息(WM_MYMSG),然后在 
    BEGIN_MESSAGE_MAP(CDecimalEdit, CEdit) 
    ON_MESSAGE(WM_MYMSG,OnMsg)
    END_MESSAGE_MAP()就可以了 再定义一个消息的结构体:想这样的:
    struct MSG
    {
       UINT MsG;
       .....;//其他的一些变量,比如控件ID等
    }
    然后 初始化一个MSG得变量A,用SendMessage(HWND hWnd, WM_MYMSG, (WPARAM )A, LPARAM lParam )发消消息
    最后在OnMsg(WPARAM wParam, LPARAM lParam)把wParam在转换为MSG类型,这样就可以取得MSG::Msg了就可以像你所说的那样统一处理了。
      

  4.   

    上网查了一下
    “判断了pMsg->message == WM_PASTE,根本进不去”
    55555555555555555555
      

  5.   

    又找到一个
    LRESULT CButtonST::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
        if (message == WM_LBUTTONDBLCLK)
        {
            message = WM_LBUTTONDOWN;
        } // if
        return CButton::DefWindowProc(message, wParam, lParam);
    } // End of DefWindowProc
      

  6.   


    // EditEx.cpp : implementation file    
    //    
       
    #include "stdafx.h"    
    #include "ControlEx.h"    
    #include "EditEx.h"    
       
    #ifdef _DEBUG    
    #define new DEBUG_NEW    
    #undef THIS_FILE    
    static char THIS_FILE[] = __FILE__;   
    #endif    
       
    /////////////////////////////////////////////////////////////////////////////    
    // CEditEx    
       
    CEditEx::CEditEx()   
    {   
    }   
       
    CEditEx::~CEditEx()   
    {   
    }   
       
       
    BEGIN_MESSAGE_MAP(CEditEx, CEdit)   
        //{{AFX_MSG_MAP(CEditEx)    
            // NOTE - the ClassWizard will add and remove mapping macros here.    
        //}}AFX_MSG_MAP    
    END_MESSAGE_MAP()   
       
    /////////////////////////////////////////////////////////////////////////////    
    // CEditEx message handlers    
       
    void CEditEx::SetNumberOnly(bool bOnly)   
    {   
        m_NumberOnly=bOnly;   
    }   
       
    BOOL CEditEx::PreTranslateMessage(MSG* pMsg)    
    {   
        // TODO: Add your specialized code here and/or call the base class    
        if(pMsg->message==WM_KEYDOWN)   
        {   
            if(pMsg->wParam==13)   
            {   
                pMsg->wParam=9; //"Tab"    
                return CEdit::PreTranslateMessage(pMsg);   
            }   
            if ((pMsg->wParam<48||pMsg->wParam>57)&&   
                pMsg->wParam!=190 && //"."    
                pMsg->wParam!=13 &&  //"Enter"    
                pMsg->wParam!=8 &&  //"Back Space"    
                m_NumberOnly==true)   
                //小键盘    
                if(pMsg->wParam<VK_NUMPAD0||PMSG->wParam>VK_NUMPAD9 &&   
                    pMsg->wParam!=110)  //小键盘上的"."    
                    pMsg->wParam=VK_CONTROL;   
        }   
       
        return CEdit::PreTranslateMessage(pMsg);   

      

  7.   


    #if !defined(AFX_EDITEX_H__F2F5DBFC_BC9E_4986_9227_BBCDA4296246__INCLUDED_) 
    #define AFX_EDITEX_H__F2F5DBFC_BC9E_4986_9227_BBCDA4296246__INCLUDED_ 
     
    #if _MSC_VER > 1000 
    #pragma once 
    #endif // _MSC_VER > 1000 
    // EditEx.h : header file 
    // 
     
    ///////////////////////////////////////////////////////////////////////////// 
    // CEditEx window 
     
    class CEditEx : public CEdit 

    // Construction 
    public: 
    CEditEx(); 
     
    // Attributes 
    public: 
     
    // Operations 
    public: 
     
    // Overrides 
    // ClassWizard generated virtual function overrides 
    //{{AFX_VIRTUAL(CEditEx) 
    public: 
    virtual BOOL PreTranslateMessage(MSG* pMsg); 
    //}}AFX_VIRTUAL 
     
    // Implementation 
    public: 
    void SetNumberOnly(bool bOnly=true); 
    virtual ~CEditEx(); 
     
    // Generated message map functions 
    protected: 
    //{{AFX_MSG(CEditEx) 
    // NOTE - the ClassWizard will add and remove member functions here. 
    //}}AFX_MSG 
     
    DECLARE_MESSAGE_MAP() 
    private: 
    bool m_NumberOnly; 
    }; 
     
    ///////////////////////////////////////////////////////////////////////////// 
     
    //{{AFX_INSERT_LOCATION}} 
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 
     
    #endif // !defined(AFX_EDITEX_H__F2F5DBFC_BC9E_4986_9227_BBCDA4296246__INCLUDED_) 
      

  8.   

    这个我可以试一试回复楼上,我已经试了
    pMsg->message == WM_PASTE
    不管用
      

  9.   

    晕,不对呀,5楼那种方法,所有消息都是自己发才行,比如我在edit上粘贴一个东西,还是不行
      

  10.   

    如果要用PreTranslateMessage。应该这样写:
    bCtrlDown = (BOOL)(UINT)(int)GetKeyState(VK_CONTROL) & 0x80000000;
    if ( bCtrlDown && ( WM_KEYDOWN == pMsg->message ) )
    {
    //CWnd* pWnd = CWnd::FromHandle(pMsg->hwnd);
    if (pMsg->hwnd == this->GetSafeHwnd())
    {
    switch( pMsg->wParam )
    {
    case 0x56: //粘贴
    {

    }
    default: break; }
    }
    }
      

  11.   

    LRESULT CDecimalEdit::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
    if (message == WM_PASTE)
    {
    AfxMessageBox(_T("1"));
    }
    return CEdit::DefWindowProc(message, wParam, lParam);
    }
    我已经试过,成功了。
      

  12.   

    因为WM_PASTE 是直接向窗口发送消息,不经过消息队列,所以PreTranslateMessage处理不了的,只有经过消息队列的消息PreTranslateMessage才处理的。