Results 1 to 5 of 5

Thread: [RESOLVED] Get the active window size

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Resolved [RESOLVED] Get the active window size

    I need to get the active window size [ Width,Height ]
    I was searching for a hours on Google but...

    I'm a beginner so I didn't really understand so much
    what ever, after playing with api and searching
    here what I got
    (put a timer1 and 2 text(text1,2)
    Code:
    Private Declare Function M_GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long
    
    Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type
    
    Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
    
    Private Function GetActiveWindow() As Long
    Dim xHwnd       As Long
    xHwnd = M_GetActiveWindow()
    GetActiveWindow = xHwnd
    End Function
    
    Sub GetWindowSize(ByVal hWnd As Long, Width As Long, Height As Long)
    Dim rc As RECT
    GetWindowRect hWnd, rc
    Width = rc.Right - rc.Left
    Height = rc.Bottom - rc.Top
    End Sub
    
    Private Sub Timer1_Timer()
    Dim rc As RECT
    Call GetWindowRect(GetActiveWindow, rc)
    Text1.Text = rc.Right - rc.Left
    Text2.Text = rc.Bottom - rc.Top
    End Sub
    the code above working with my form,but not working for other program windows
    it should get the size of any active window
    please edit the code above or if there is a better way to do what I'm looking for
    any help would be appreciate
    thanks in advance.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Get the active window size

    What are you trying to do here? Are you just trying to move the text box on your form based on the size of whatever window is active? If so that doesn't make a lot of sense to do if not then I can't guess what you are trying to do so you would need to be more descriptive of what you are trying to do and what problems you are facing.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Re: Get the active window size

    Quote Originally Posted by DataMiser View Post
    What are you trying to do here? Are you just trying to move the text box on your form based on the size of whatever window is active? If so that doesn't make a lot of sense to do if not then I can't guess what you are trying to do so you would need to be more descriptive of what you are trying to do and what problems you are facing.
    I trying to get window width and height
    not my program window, any other program window.

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: Get the active window size

    Use the GetForeGroundWindow API function instead of GetActiveWindow:
    Code:
    Private Declare Function GetForegroundWindow Lib "User32.dll" () As Long

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Re: Get the active window size

    Quote Originally Posted by Peter Swinkels View Post
    Use the GetForeGroundWindow API function instead of GetActiveWindow:
    Code:
    Private Declare Function GetForegroundWindow Lib "User32.dll" () As Long
    Million of thanks for you ♥

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