Private Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long
Option Explicit Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End TypePrivate lpRect As RECT Private cHwnd As LongPrivate Sub Command1_Click() cHwnd = FindWindow(vbNullString, "示例工程") '查找窗体, "示例工程改为你要查找的窗体的名称" Me.AutoRedraw = True Me.Cls If cHwnd <> 0 Then '如果查找到就做以下动作 GetWindowRect cHwnd, lpRect Me.Print "窗体的Left坐标是:" & Screen.TwipsPerPixelX * lpRect.Left Me.Print "窗体的Top坐标是:" & Screen.TwipsPerPixelX * lpRect.Top Me.Print "窗体的Width是:" & Screen.TwipsPerPixelX * (lpRect.Right - lpRect.Left) Me.Print "窗体的Heidht是:" & Screen.TwipsPerPixelX * (lpRect.Bottom - lpRect.Top) Else Me.Print "没有找到窗体" End If End Sub
Option Explicit
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate lpRect As RECT
Private cHwnd As LongPrivate Sub Command1_Click()
cHwnd = FindWindow(vbNullString, "示例工程") '查找窗体, "示例工程改为你要查找的窗体的名称"
Me.AutoRedraw = True
Me.Cls
If cHwnd <> 0 Then '如果查找到就做以下动作
GetWindowRect cHwnd, lpRect
Me.Print "窗体的Left坐标是:" & Screen.TwipsPerPixelX * lpRect.Left
Me.Print "窗体的Top坐标是:" & Screen.TwipsPerPixelX * lpRect.Top
Me.Print "窗体的Width是:" & Screen.TwipsPerPixelX * (lpRect.Right - lpRect.Left)
Me.Print "窗体的Heidht是:" & Screen.TwipsPerPixelX * (lpRect.Bottom - lpRect.Top)
Else
Me.Print "没有找到窗体"
End If
End Sub
现在这个是以 Twips (缇)为单位的.