我创建了一个VC的工程。划分2个客户区,一个客户区继承CFrameWnd类,在这个客户区动态创建一个CButton ,创建出来了,但是不能响应我的消息函数。为什么?BEGIN_MESSAGE_MAP(CMFMUBindView, CFrameWnd)
//{{AFX_MSG_MAP(CMFMUBindView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_CONTROL_REFLECT(5667,OnBnCl)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMFMUBindView message handlersint CMFMUBindView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
b.Create("hehe",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,100), this, 5667);// b.ShowWindow(SW_SHOWNORMAL);  return 0;
}void CMFMUBindView::OnSize(UINT nType, int cx, int cy) 
{
CFrameWnd::OnSize(nType, cx, cy);

// TODO: Add your message handler code here

}
void CMFMUBindView::OnBnCl() 
{ AfxMessageBox("11");

// TODO: Add your message handler code here

}
class CMFMUBindView : public CFrameWnd
{
DECLARE_DYNCREATE(CMFMUBindView)
protected:
CMFMUBindView();           // protected constructor used by dynamic creation// Attributes
public:
CMFButton b;
// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMFMUBindView)
//}}AFX_VIRTUAL// Implementation
protected:
virtual ~CMFMUBindView(); // Generated message map functions
//{{AFX_MSG(CMFMUBindView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnBnCl();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

解决方案 »

  1.   

    重载了一button类,在里面响应你的消息,想怎么干就怎么干。
      

  2.   

    我是重载了一个cbutton  上面有  CMFButton   试过了还是不行。
      

  3.   

    Button 的ID 和接收消息的ID对不对啊
      

  4.   

    你是通过向导建立的消息函数还是自己手动添加的?如果是自己手动添加的把ON_CONTROL_REFLECT(5667,OnBnCl)从//{{AFX_MSG_MAP(CMFMUBindView) ...//}}AFX_MSG_MAP 中移出来试试看
      

  5.   

    //{{AFX_MSG_MAP(CMFMUBindView) 
    ON_WM_CREATE() 
    ON_WM_SIZE() 
    ON_CONTROL_REFLECT(5667,OnBnCl) 
    //}}AFX_MSG_MAP 
    动态创建的哪来的这个?