Results 1 to 2 of 2

Thread: Sending and Recieving information about a window, by knowing it's caption ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Posts
    87

    Post

    How can I recieve a windows Width, Height, Top, Left, by just knowing it's caption or hWnd ?

    And how can I resize a window to any Height, Width, Top, Left, that I want, by just knowing the windows hWnd or Caption ?

    The Windows is not part of my program, like, how do I resize Windows Explorer, from within my program, and know it's current size ?

    Please help me.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    You can try something like this:

    Code:
    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 Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    
    Private Sub Form_Load()
        Dim lHwnd As Long
        Dim rc As RECT
        Dim strMsg As String
        
        lHwnd = FindWindowEx(0, 0, vbNullString, "CaptionOfProgram")
        Call GetWindowRect(lHwnd, rc)
        strMsg = "Height: " & rc.Bottom - rc.Top & vbCrLf
        strMsg = strMsg & "Width: " & rc.Right - rc.Left & vbCrLf
        strMsg = strMsg & "Top: " & rc.Top & vbCrLf
        strMsg = strMsg & "Left: " & rc.Left
    End Sub
    Just substitute CaptionOfProgram with the appropriate caption.

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