Results 1 to 4 of 4

Thread: [RESOLVED] get size of a window?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: get size of a window?

    alrighty, thanks, i'll do some research then post back.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    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
  •  



Click Here to Expand Forum to Full Width