ウィンドウのサイズを取得
Declare Function GetWindowRect Lib "user32.dll" _
(ByVal hWnd As Long, lpRect As Rect) As Long
Declare Function GetWindowRect Lib "user32.dll" _
(ByVal hWnd As Integer, lpRect As Rect) As Integer
BOOL GetWindowRect(
HWND hWnd,
LPRECT lpRect
);
引数
hWnd
ウィンドウのハンドルlpRect
(戻り値)サイズを受け取るRECT構造体戻り値
正常終了のとき 0以外備考
エラーのとき 0
ウィンドウサイズは、境界線、スクロールバー、メニューバー等も含む。サンプル
ダウンロード(GetWindowRect.lzh 1.78KB)
Private Sub Timer1_Timer()
Me.List1.Clear
Dim rc As Long, lpRect As RECT
Dim Pos As PointApi, hWnd As Long
Dim Temp As String
'現在のマウス位置を取得
rc = GetCursorPos(Pos)
'現在のマウス位置にあるウィンドウのハンドル取得
hWnd = WindowFromPoint(Pos.X, Pos.Y)
'関数の実行
Call GetWindowRect(hWnd, lpRect)
'タイトル取得
Temp = String(256, Chr(0))
Call GetWindowText(hWnd, Temp, Len(Temp))
a = InStr(Temp, Chr(0))
If a > 1 Then
Temp = Mid(Temp, 1, a - 1)
Else
Temp = ""
End If
'表示
With Me.List1
.AddItem Temp
.AddItem ""
.AddItem "左上隅のX座標 :" + Str(lpRect.Left)
.AddItem "同、Y座標 :" + Str(lpRect.Top)
.AddItem "右下隅のX座標 :" + Str(lpRect.Right)
.AddItem "同、Y座標 :" + Str(lpRect.Bottom)
End With
End Sub