how can i get the height and width of a window in an external application?
Printable View
how can i get the height and width of a window in an external application?
You can call the GetWindowRect API function. You can then calculate the dimensions from the RECT structure it populates. You need the handle of the Window to pass to that function, so you'd use the FindWindow API. You'll defeinitely find plenty of examples of that one around, but maybe fewer for GetWindowRect. It's fairly simply though so, if you know how to call Windows API functions, it's not hard to work put for yourself.
alrighty, thanks, i'll do some research then post back.
i figured it out.
Code:Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
Sub getResolution()
Dim nWnd As IntPtr
Dim ceroIntPtr As New IntPtr(0)
Dim Wnd_name As String
Wnd_name = "Untitled - Notepad"
nWnd = FindWindow(Nothing, Wnd_name)
Dim hwnd As Integer = nWnd
Dim rectWindow As New RECT
If GetWindowRect(hwnd, rectWindow) = 0 Then
Label6.Text = "Could not find hWnd"
Else
Label6.Text = rectWindow.Right - rectWindow.Left & "x" & rectWindow.Bottom - rectWindow.Top
resTop = rectWindow.Top
resLeft = rectWindow.Left
resBottom = rectWindow.Bottom
resRight = rectWindow.Right
End If
End Sub