我想用钩子抓鼠标的坐标,下面的代码有三处错误,大家帮我看看(100分)

  • 主题发起人 主题发起人 spsyd
  • 开始时间 开始时间
S

spsyd

Unregistered / Unconfirmed
GUEST, unregistred user!
在CChildView::OnPaint()添加如下代码: <br><br>&nbsp; &nbsp; &nbsp; &nbsp; CPaintDC dc(this); <br> char str[256];<br> sprintf(str,“x=%d,y=%d",point.x,point.y);<br>&nbsp; &nbsp; //构造字符串<br> dc.TextOut(0,0,str); //显示字符串<br><br>----(2)childview.cpp文件中定义全局的鼠标勾子函数。 <br><br>LRESULT CALLBACK MouseProc<br>(int nCode, WPARAM wParam, LPARAM lParam)<br>{//是鼠标移动消息<br>if(wParam==WM_MOUSEMOVE||wParam(这里出错)<br>&nbsp; &nbsp; ==WM_NCMOUSEMOVE) <br>{<br>point=((MOUSEHOOKSTRUCT *)lParam)-&gt;pt;<br>&nbsp; &nbsp; //取鼠标信息<br>pView-&gt;Invalidate(); //窗口重画<br>}<br>return CallNextHookEx(hHook,nCode,wParam,lParam); <br>&nbsp; //传递勾子信息<br>}<br>&nbsp; &nbsp; (3)CChildView类的构造函数中安装勾子。<br>CChildView::CChildView()<br>{<br> pView=this;//获得输出窗口指针<br> hHook=SetWindowsHookEx(这里也有问题)<br>&nbsp;(WH_MOUSE,MouseProc,0,GetCurrentThreadId());<br>}<br>&nbsp; &nbsp; (4)CChildView类的析构函数中卸载勾子。<br>CChildView::~CChildView()<br>{ <br> if(hHook)<br> UnhookWindowsHookEx(hHook);<br>}<br>
 
LRESULT CALLBACK MouseProc (int nCode, WPARAM wParam, LPARAM lParam)<br>{//是鼠标移动消息<br>&nbsp;if (nCode &gt;= 0)<br>&nbsp;{<br>&nbsp; &nbsp; point=((MOUSEHOOKSTRUCT *)lParam)-&gt;pt;<br>&nbsp; &nbsp; &nbsp;//取鼠标信息<br>&nbsp; &nbsp; pView-&gt;Invalidate(); //窗口重画<br>&nbsp; }<br>return CallNextHookEx(hHook,nCode,wParam,lParam); <br>&nbsp; //传递勾子信息<br>}<br>&nbsp; &nbsp; (3)CChildView类的构造函数中安装勾子。<br>CChildView::CChildView()<br>{<br> pView=this;//获得输出窗口指针<br> hHook=SetWindowsHookEx(这里也有问题)<br>&nbsp;(WH_MOUSE,MouseProc,hInstance,0);<br>}<br>&nbsp; &nbsp; (4)CChildView类的析构函数中卸载勾子。<br>CChildView::~CChildView()<br>{ <br> if(hHook)<br> UnhookWindowsHookEx(hHook);<br>}<br>要在DLL里面
 
在CChildView::OnPaint()添加如下代码: <br><br>&nbsp; &nbsp; &nbsp; &nbsp; CPaintDC dc(this); <br> char str[256];<br> sprintf(str,“x=%d,y=%d",point.x,point.y);<br>&nbsp; &nbsp; //构造字符串<br> dc.TextOut(0,0,str); //显示字符串<br><br>----(2)childview.cpp文件中定义全局的鼠标勾子函数。 <br><br>LRESULT CALLBACK MouseProc<br>(int nCode, WPARAM wParam, LPARAM lParam)<br>{//是鼠标移动消息<br><br><br>-----------------------------------------------<br>if(wParam==WM_MOUSEMOVE||wParam(这里出错)<br>&nbsp; &nbsp; ==WM_NCMOUSEMOVE) <br>-------------------------------------------------<br>if (wParam==wm_MouseMove)||(WParam==wm_NCMouseMove)<br>-------------------------------------------------------<br><br>{<br>point=((MOUSEHOOKSTRUCT *)lParam)-&gt;pt;<br>&nbsp; &nbsp; //取鼠标信息<br>pView-&gt;Invalidate(); //窗口重画<br>}<br>return CallNextHookEx(hHook,nCode,wParam,lParam); <br>&nbsp; //传递勾子信息<br>}<br>&nbsp; &nbsp; (3)CChildView类的构造函数中安装勾子。<br>CChildView::CChildView()<br>{<br> pView=this;//获得输出窗口指针<br> hHook=SetWindowsHookEx(这里也有问题)--有什么问题?<br>&nbsp;(WH_MOUSE,MouseProc,0,GetCurrentThreadId());<br>}<br>&nbsp; &nbsp; (4)CChildView类的析构函数中卸载勾子。<br>CChildView::~CChildView()<br>{ <br> if(hHook)<br> UnhookWindowsHookEx(hHook);<br>}<br>
 
多人接受答案了。
 
后退
顶部