CWND对象鼠标中键事件响应,除了重写相应的消息响应函数外,还有一个很重要的是该对象要获取焦点后才能响应,具体实现如下
.h文件
protected:
//{{AFX_MSG(CChartRightRule)
//NOTE - the ClassWizard will add and remove member function here.
afx_msg void OnMouseMove(UINT nFlags, CPoint point); //用于设置僬点
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); //具体的中键响应函数
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
.CPP文件
//关联
BEGIN_MESSAGE_MAP(CChartRightRule, CWnd)
//{{AFX_MSG_MAP(CChartRightRule)
//NOTE - the ClassWizard will add and remove mapping macros here.
ON_WM_MOUSEMOVE()
ON_WM_MOUSEWHEEL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
实现
void CChartRightRule::OnMouseMove(UINT nFlags, CPoint point)
{
this->SetFocus();
}
BOOL CChartRightRule::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TRACE("\r\nzDelta:%d", zDelta);
if (zDelta < 0)
m_aRightRule.nMax -= 50; //下滚
else
m_aRightRule.nMax += 50; ////上滚
//Invalidate();
return CWnd::OnMouseWheel(nFlags, zDelta, pt);
}