|
-
Aug 4th, 2012, 11:32 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] get size of a window?
how can i get the height and width of a window in an external application?
Last edited by Justa Lol; Aug 4th, 2012 at 11:33 PM.
Reason: forgot prefix
-
Aug 5th, 2012, 08:39 AM
#2
Re: get size of a window?
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.
-
Aug 5th, 2012, 07:26 PM
#3
Thread Starter
Fanatic Member
Re: get size of a window?
alrighty, thanks, i'll do some research then post back.
-
Aug 5th, 2012, 10:37 PM
#4
Thread Starter
Fanatic Member
Re: [RESOLVED] get size of a window?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|