试了几下,GetWindowRect 都无法获取正确的值,不知道什么原因,不玩了。可以自己试试
全局代码
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Structure myRECT '自定义区域结构类型
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
Public ActiveWindowRECT As myRECT '用於保存活动窗口区域的结构
Public ActiveWindowHwnd As Long '活动窗口的句柄
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, ByRef wndRect As myRECT) As Boolean
调用测试
Dim ret = FindWindow(vbNullString, "命令窗口")
Output.Show(ret)
ActiveWindowHwnd = GetForegroundWindow
Output.Show(ActiveWindowHwnd )
Dim aa As new myRECT
Dim lng As Boolean = GetWindowRect(ret, aa)
Output.Show(lng)
Output.Show("活动窗口的坐标是(" & aa.left & "," & aa.Top & "," & aa.Right & "," & aa.Bottom & ")")
lng = GetWindowRect(ActiveWindowHwnd , ActiveWindowRECT )
Output.Show(lng)
Output.Show("活动窗口的坐标是(" & ActiveWindowRECT .left & "," & ActiveWindowRECT .Top & "," & ActiveWindowRECT .Right & "," & ActiveWindowRECT .Bottom & ")")