64,647
社区成员
发帖
与我相关
我的任务
分享
我如何在我的CTool中响应鼠标消息呢,前提是这个类的构造函数我已经传递进来了CView类的指针this
汗~~~lz应该理解偏差了吧?
鼠标消息的响应,不可能在CTool里去响应啊,应该在CView里响应,然后响应函数或者响应的处理过程可以放在CTool里
应该不能在CTool里捕捉到鼠标消息吧?!
除非CTool能从某个CView里继承过来
不知道说的对不对,仅供参考!
视图类.h
class CMyView: public CView
{
protected:
CMyView();
virtual ~CMyView();
DECLARE_DYNCREATE(CMyView)
protected:
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP()
private:
CTool* m_Tool;
};
视图类.cpp
BEGIN_MESSAGE_MAP(CMyView, CView)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
CClientDC dc(this);
OnPrepareDC(&dc,NULL);
dc.DPtoLP(&point);
ASSERT(m_Tool);
m_Tool->OnLButtonDown(this,nFlags,point);
CView::OnLButtonDown(nFlags, point);
}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{
CClientDC dc(this);
OnPrepareDC(&dc,NULL);
dc.DPtoLP(&point);
ASSERT(m_Tool);
m_Tool->OnLButtonUp(this,nFlags,point);
CView::OnLButtonUp(nFlags, point);
}
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc(this);
OnPrepareDC(&dc,NULL);
dc.DPtoLP(&point);
ASSERT(m_Tool);
m_Tool->OnMouseMove(this,nFlags,point);
CView::OnMouseMove(nFlags, point);
}
CTool类的.h
public:
void OnLButtonUp(CView* pView, UINT nFlags, const CPoint& point);
void OnLButtonDown(CView* pView, UINT nFlags, const CPoint& point);
void OnMouseMove(CView* pView, UINT nFlags, const CPoint& point);
CTool类的.cpp
void CTool::OnLButtonDown(CView* pView, UINT nFlags, const CPoint& point)
{
// 处理代码
}
void CTool::OnLButtonUp(CView* pView, UINT nFlags, const CPoint& point)
{
// 处理代码
}
void CTool::OnMouseMove(CView* pView, UINT nFlags, const CPoint& point)
{
// 处理代码
}