VB怎么获取当前活动窗口的坐标?
3个回答
推荐于2018-03-23
展开全部
'在窗体上画一个Timer控件,设置其Interval属性为100
'把代码复制到Form1的代码窗口中
'获得活动窗口句柄的API
Private Declare Function GetForegroundWindow Lib "user32" () As Long
'获得窗口区域结构的API
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, wndRect As RECT) As Long
Private Type RECT '自定义区域结构类型
x As Long
y As Long
Right As Long
Bottom As Long
End Type
Dim ActiveWindowRECT As RECT '用於保存活动窗口区域的结构
Dim ActiveWindowHwnd As Long '活动窗口的句柄
Private Sub Timer1_Timer()
ActiveWindowHwnd = GetForegroundWindow '获得活动窗口的句柄
GetWindowRect ActiveWindowHwnd, ActiveWindowRECT '获得活动窗口的区域并保存在 ActiveWindowRECT 变量中
'在窗口上输出信息
Me.Cls
Print "活动窗口的坐标是(" & ActiveWindowRECT.x & "," & ActiveWindowRECT.y & ")"
End Sub
'把代码复制到Form1的代码窗口中
'获得活动窗口句柄的API
Private Declare Function GetForegroundWindow Lib "user32" () As Long
'获得窗口区域结构的API
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, wndRect As RECT) As Long
Private Type RECT '自定义区域结构类型
x As Long
y As Long
Right As Long
Bottom As Long
End Type
Dim ActiveWindowRECT As RECT '用於保存活动窗口区域的结构
Dim ActiveWindowHwnd As Long '活动窗口的句柄
Private Sub Timer1_Timer()
ActiveWindowHwnd = GetForegroundWindow '获得活动窗口的句柄
GetWindowRect ActiveWindowHwnd, ActiveWindowRECT '获得活动窗口的区域并保存在 ActiveWindowRECT 变量中
'在窗口上输出信息
Me.Cls
Print "活动窗口的坐标是(" & ActiveWindowRECT.x & "," & ActiveWindowRECT.y & ")"
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-24
展开全部
'下面是代码,直接复制就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-24
展开全部
使用API
GetWindowsPos()
GetWindowsPos()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询