VB获取窗口内某一点的坐标
求能够获取在指定某窗口内某一点的坐标!!PS:指定某窗口内~~~~不是整个屏幕!请看仔细,谢谢了!!PS:主要用于获取其他窗口内某一点的坐标,PrivateSubForm...
求能够获取在指定某窗口内某一点的坐标!!
PS:指定某窗口内~~~~不是整个屏幕!请看仔细,谢谢了!!
PS:主要用于获取其他窗口内某一点的坐标,
Private Sub Form_MouseUp
这样不是只能在form窗体点击才有用?那有什么意义?不明白?
PSPSPSP:
是我没听懂还是你们没听懂呢?
我要的是获取指定的其他窗口(比如说蜘蛛纸牌里)的某一点坐标,
你们这样不是只能获取在这个VB工程窗体里的某一点,这并不是我要的!? 展开
PS:指定某窗口内~~~~不是整个屏幕!请看仔细,谢谢了!!
PS:主要用于获取其他窗口内某一点的坐标,
Private Sub Form_MouseUp
这样不是只能在form窗体点击才有用?那有什么意义?不明白?
PSPSPSP:
是我没听懂还是你们没听懂呢?
我要的是获取指定的其他窗口(比如说蜘蛛纸牌里)的某一点坐标,
你们这样不是只能获取在这个VB工程窗体里的某一点,这并不是我要的!? 展开
3个回答
展开全部
窗体中加入一个Timer,代码如下:
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 = 15
End Sub
Private Sub Timer1_Timer()
Dim pt As POINTAPI
Dim wfp As WINDOWPLACEMENT
Dim myhwnd As Long
Dim r As Long
GetCursorPos pt
myhwnd = WindowFromPoint(pt.x, pt.y)
r = GetWindowPlacement(myhwnd, wfp)
Cls
Print "Current hWnd:" & myhwnd
Print "X:" & pt.x - wfp.rcNormalPosition.Left
Print "Y:" & pt.y - wfp.rcNormalPosition.Top
End Sub
该代码可以得到鼠标在所指的窗体中的相对坐标
上面的myhwnd为窗体句柄。
当然除了WindowFromPoint函数,你也可以使用getwindowlong或者getforegruondwindow等函数获得窗体句柄。
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 = 15
End Sub
Private Sub Timer1_Timer()
Dim pt As POINTAPI
Dim wfp As WINDOWPLACEMENT
Dim myhwnd As Long
Dim r As Long
GetCursorPos pt
myhwnd = WindowFromPoint(pt.x, pt.y)
r = GetWindowPlacement(myhwnd, wfp)
Cls
Print "Current hWnd:" & myhwnd
Print "X:" & pt.x - wfp.rcNormalPosition.Left
Print "Y:" & pt.y - wfp.rcNormalPosition.Top
End Sub
该代码可以得到鼠标在所指的窗体中的相对坐标
上面的myhwnd为窗体句柄。
当然除了WindowFromPoint函数,你也可以使用getwindowlong或者getforegruondwindow等函数获得窗体句柄。
展开全部
一、函数声明:
Type PointAPI
x As Long
y As Long
End Type
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As PointAPI) As Long
二、调用举例:
假如已知目标窗口的Hwnd,其内部某点相对于屏幕的坐标为x,y
那么,该点相对于窗口内的坐标为:
Dim lu_POINT As PointAPI
lu_POINT.x = x
lu_POINT.y = y
ScreenToClient DstWnd, lu_POINT
此时,返回的lu_POINT.x、lu_POINT.y就是内部坐标了。
Type PointAPI
x As Long
y As Long
End Type
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As PointAPI) As Long
二、调用举例:
假如已知目标窗口的Hwnd,其内部某点相对于屏幕的坐标为x,y
那么,该点相对于窗口内的坐标为:
Dim lu_POINT As PointAPI
lu_POINT.x = x
lu_POINT.y = y
ScreenToClient DstWnd, lu_POINT
此时,返回的lu_POINT.x、lu_POINT.y就是内部坐标了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Cls
Print X, Y
End Sub
把鼠标在窗体内移动就会在窗体上打印出坐标,单位是twip
你可以根据需要修改度量单位,加一句scalemode=3 就是像素,还有其他的,自己改吧
Cls
Print X, Y
End Sub
把鼠标在窗体内移动就会在窗体上打印出坐标,单位是twip
你可以根据需要修改度量单位,加一句scalemode=3 就是像素,还有其他的,自己改吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询