如何在VB中捕捉鼠标的位置(包括任务栏)?

youhwa 2003-10-20 10:17:02
我想在VB中捕捉鼠标的位置,但鼠标位置可能在任务栏上,也就是说不在VB的应用程序界面里,该如何捕捉??
谢谢各位大虾指点。
...全文
79 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
射天狼 2003-10-22
  • 打赏
  • 举报
回复
属于田鸭类型的~~
programfish 2003-10-20
  • 打赏
  • 举报
回复
GetCursorPos
zhangqs 2003-10-20
  • 打赏
  • 举报
回复
Public Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Rongxian 2003-10-20
  • 打赏
  • 举报
回复
用API的GetCursorPos
射天狼 2003-10-20
  • 打赏
  • 举报
回复
用API函数,在TIMER控件里调用就可以了!!

Public Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long

Micro_Sheng 2003-10-20
  • 打赏
  • 举报
回复
1、先把以下代码放入一个单独的模块中

Public Type POINTAPI
x As Long
y As Long
End Type

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Public Function GetMousePos() As POINTAPI
Dim MousePos As POINTAPI
Dim rel As Long

rel = GetCursorPos(MousePos)
GetMousePos = MousePos

End Function


2、在你的窗体放置一个Timer控件(Enabled=true Interval=100)、两个Label控件(Label1、Label2),再把以下代码放入窗体代码窗口中

Private Sub Timer1_Timer()

Label1 = CStr(GetMousePos.x)
Label2 = CStr(GetMousePos.y)

End Sub

3、直接运行程序,这时你不管把鼠标放什么地方都能显示出它的坐标!

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧