
vb 如何获取指定程序的窗口内的鼠标坐标
不是整个屏幕的坐标,是指定程序窗口的坐标......比如记事本..的...怎么获得记事本内的鼠标位置的x,y值...或者说可以用记事本的窗口坐标-去屏幕的鼠标坐标?...
不是整个屏幕的坐标,是指定程序窗口的坐标......
比如记事本..的...
怎么获得记事本内的鼠标位置的x,y值...
或者说可以用记事本的窗口坐标-去屏幕的鼠标坐标? 展开
比如记事本..的...
怎么获得记事本内的鼠标位置的x,y值...
或者说可以用记事本的窗口坐标-去屏幕的鼠标坐标? 展开
2个回答
展开全部
这个是我编写的用来取得窗口位置信息的程序
你把鼠标位置减去窗口位置 得到相对位置
'***************************************************************
'***该程序可以通过鼠标指针的位置判断鼠标所指的窗口的参数
'***辽宁大学。物理学院 yoya0303
'***************************************************************
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Dim pt As POINTAPI
Dim wfp As WINDOWPLACEMENT
Dim x As Long
Dim ret As Long
GetCursorPos pt
x = WindowFromPoint(pt.x, pt.y)
ret = GetWindowPlacement(x, wfp)
Label1.Caption = wfp.rcNormalPosition.Left '窗口距屏幕左边距离
Label2.Caption = wfp.rcNormalPosition.Right '窗口距屏幕右边距离
Label3.Caption = wfp.rcNormalPosition.Top '窗口距屏幕顶距离
Label4.Caption = wfp.rcNormalPosition.Bottom '窗口距屏幕底距离
End Sub
你把鼠标位置减去窗口位置 得到相对位置
'***************************************************************
'***该程序可以通过鼠标指针的位置判断鼠标所指的窗口的参数
'***辽宁大学。物理学院 yoya0303
'***************************************************************
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Dim pt As POINTAPI
Dim wfp As WINDOWPLACEMENT
Dim x As Long
Dim ret As Long
GetCursorPos pt
x = WindowFromPoint(pt.x, pt.y)
ret = GetWindowPlacement(x, wfp)
Label1.Caption = wfp.rcNormalPosition.Left '窗口距屏幕左边距离
Label2.Caption = wfp.rcNormalPosition.Right '窗口距屏幕右边距离
Label3.Caption = wfp.rcNormalPosition.Top '窗口距屏幕顶距离
Label4.Caption = wfp.rcNormalPosition.Bottom '窗口距屏幕底距离
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询