CDialog接收不到自定义按钮的onclick事件
关于这个问题,我看到有人在2004年提出过,不知道当时解决了没。
http://bbs.csdn.net/topics/50435702
具体的描述如下:
我重载了Button,并对OnPaint、OnLButtonDown、OnLButtonUp、OnEraseBkgnd这四个事件进行了处理。但是发现在CDialog无法触发重载按钮的onclick事件。
重载按钮的代码如下:
class CMyBitmapButton : public CButton
{
DECLARE_DYNAMIC(CMyBitmapButton)
public:
CMyBitmapButton();
~CMyBitmapButton();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};
IMPLEMENT_DYNAMIC(CMyBitmapButton, CBitmapButton)
CMyBitmapButton::CMyBitmapButton()
{
}
CMyBitmapButton::~CMyBitmapButton()
{
}
BEGIN_MESSAGE_MAP(CMyBitmapButton, CBitmapButton)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
void CMyBitmapButton::OnLButtonDown(UINT nFlags, CPoint point)
{
//todo
}
void CMyBitmapButton::OnLButtonUp(UINT nFlags, CPoint point)
{
//todo
}
void CMyBitmapButton::OnPaint()
{
//todo
}
void CMyBitmapButton::OnEraseBkgnd(CDC* pDC)
{
//todo
}
BEGIN_MESSAGE_MAP(CDlgLobby, CDialog)
...
ON_BN_CLICKED(IDC_TABLE_1_1, &CDlgLobby::OnSelectTable1)
...
END_MESSAGE_MAP()
CMyBitmapButton m_hTable1_1;
m_hTable1_1.SubclassDlgItem(IDC_TABLE_1_1, this);
CButton::OnLButtonDown(nFlags, point);
}
[解决办法]
class CMyBitmapButton : public CButton
BEGIN_MESSAGE_MAP(CMyBitmapButton, CBitmapButton)
这2个好像没对应啊,要么都是CButton,要么都是CBitmapButton