GetWindowRect
要取得視窗的高度及寬度,我們可以用GetWindowRect這API函數,其宣告法是:
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
Dim WindowRect as RECT
用法:
GetWindowRect hWnd, WindowRect 'hWnd為某視窗的hWnd值
MsgBox "某視窗的X軸位置: " & WindowRect.Left & vbCrLf & _
"某視窗的Y軸位置: " & WindowRect.Top & vbCrLf & _
"某視窗的寬度: " & WindowRect.Right - WindowRect.Left & vbCrLf & _
"某視窗的高度: " & WindowRect.Bottom - WindowRect.Top, vbInformation, "某視窗資料"
實戰個案: