How do I get the width and height of a window? Let's say I, an end user, open Chrome in a window, and then resize it. How can I, an end user, find out how large the window is now? Chrome is just an example; I am looking for how to do this with any application in a window.
Asked
Active
Viewed 1.5k times
4 Answers
4
You could use a simple tool like WinSpy or the Window Spy tool included in the AutoHotKey package.
3
You can make your own
Copy following two files to a folder.
To Use:
GetWindowRect <Title Of Window>
EG
GetWindowRect Untitled - Notepad
Change /target:exe to /target:winexe to make it a non console program
REM GetWindowRect.bat
REM This file compiles GetWindowRect.vb to GetWindowRect.exe
REM GetWindowRect.exe reports on Windows position
REM To use
REM GetWindowRect
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\GetWindowRect.exe" "%~dp0\GetWindowRect.vb"
pause
;GetWindowRect.vb
imports System.Runtime.InteropServices
Public Module GetWindowRect
<StructLayout(LayoutKind.Sequential)> _
Private Structure RECTL
Public Left As UInt32
Public Top As UInt32
Public Right As UInt32
Public Bottom As UInt32
End Structure
Private Declare Function GetWindowRect Lib "User32" (ByVal hWnd as IntPtr, ByRef Rect as RectL) as Integer
Public Declare UNICODE Function FindWindowW Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Sub Main
On Error Resume Next
Dim hWindows as IntPtr
Dim Ret as Integer
hwindows = FindWindowW(vbNullString, Command())
If hwindows = 0 then
Msgbox(Command() & " cannot be found.")
Else
Dim x as RectL
Ret = GetWindowRect(hWindows, x)
If Ret = 0 Then
MsgBox("GetWindowRect Error " & Err.LastDllError)
Else
'Delete the MsgBox line if using as console program
Msgbox(x.left & " " & x.top & " " & x.right & " " & x.bottom)
Console.Writeline(x.left & " " & x.top & " " & x.right & " " & x.bottom)
End If
End If
End Sub
End Module
Also available here - https://winsourcecode.blogspot.com/2020/01/getwindowrectexe-reports-on-windows.html
Mark
- 854
2
Use the Snipping Tool to capture a screenshot of the window, and then look at the properties of the screenshot to see the dimensions of the window.
McHobbes
- 131
2
My fastest way :
- Alt + Print Screen
- Open paint and reduce Canvas
- Ctrl + V
The size of the window is in the status bar
DarkDiamond
- 1,919
- 11
- 15
- 21
novaXire
- 21