看错了
Private Sub Timer1_Timer()
Dim lPoint As POINTAPI
Call GetCursorPos(lPoint)
Dim hWnd1 As Long
hWnd1 = WindowFromPoint(lPoint.X, lPoint.Y)
' hWnd1 = GetForegroundWindow()
Dim lRect As RECT
Call GetWindowRect(hWnd1, lRect)
Debug.Print "left:" & lRect.Left & ";top:" & lRect.Top & ";right:" & lRect.Right & ";bottom:" & lRect.Bottom
End Sub
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Timer1_Timer()
Dim hWnd1 As Long
hWnd1 = GetForegroundWindow()
Dim lRect As RECT
Call GetWindowRect(hWnd1, lRect)
Debug.Print "left:" & lRect.Left & ";top:" & lRect.Top & ";right:" & lRect.Right & ";bottom:" & lRect.Bottom
End Sub
Option Explicit
'获取目前选择的鼠标指针的句柄
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'返回包含了指定点的窗口的句柄
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
'取得一个窗体的标题文字
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'为指定的窗口取得类名
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'从指定窗口的结构中取得信息
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long