为什么用这方法得不到鼠标的屏幕坐标?(100分)

G

g_feng

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; Application.OnMessage := AppMessage;<br>end;<br>procedure TForm1.AppMessage(var msg:TMsg;var handled:Boolean);<br>var xpos: integer;<br>&nbsp; &nbsp; ypos: integer;<br>&nbsp; &nbsp; MousePos: TPoint;<br>begin<br>&nbsp; &nbsp;if (Msg.message = WM_MouseMove) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;MousePos.X := LOWORD(msg.lParam);<br>&nbsp; &nbsp; &nbsp;Mousepos.Y := HIWORD(msg.lParam);<br>&nbsp; &nbsp; &nbsp;windows.ClientToScreen(msg.hwnd,MousePos);<br>&nbsp; &nbsp; &nbsp;Label1.Caption := inttostr(MousePos.X);<br>&nbsp; &nbsp; &nbsp;label2.Caption := inttostr(Mousepos.Y);<br>&nbsp; &nbsp;end;<br>end;<br>以上程序为得不到鼠标的屏幕坐标?
 
我测试你你的代码,可以用呀。你是不是没有讲FormCreate事件与相应的方法关联?
 
确实可以用的,你谦虚了,哈哈)
 
您要什么效果先???????<br>做什么啊~~~~
 
屏幕是指form还是screen
 
[purple]我也得不到,得到的坐标是错误![/purple]
 
[blue]直接用getcursorpos就可以得到当前的坐标![/blue]
 
[gold]在onmousemove事件里,Label1.Caption := inttostr(Mouse。cursorpos.X);<br>&nbsp; &nbsp; &nbsp;label2.Caption := inttostr(Mouse。cursorpos.Y);<br>就可以动态的显示鼠标的当前坐标![/gold]
 
[blue]缺点是只能得到onmousemove事件所属的控件范围内[/blue]
 
是你没用鼠标HOOK的缘故吧![:D]
 
看来的确是这样,我在Form里得到的只是发到这个Form里的消息,所以当鼠标在外面时我只能<br>用hook才能控制,但DELPHI的自带消息cm_MouseLeave和cm_MouseEnter是根据什么原理产生的呢?
 
&nbsp;var p:Tpoint ;<br>begin<br>&nbsp; GetCursorPos(p);<br>&nbsp; Label1.Caption := IntToStr(p.X);<br>&nbsp; Label2.Caption := IntToStr(p.y);<br>end;<br>
 
多人接受答案了。
 
顶部