Results 1 to 4 of 4

Thread: How to get the handle of a window thats behind another window

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Location
    Singapore
    Posts
    24

    Question

    Does anyone knows how you can get the handle of a window thats behind another window. I have an application running on top of internet explorer, i need to get the handle of internet explorer thats behind the application. Please help mi, i'm new to this.
    Thanks

  2. #2
    Guest
    Use the FindWindow API function.


    Code:
    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    
    
    Private Sub Command1_Click()
    
        hWin = FindWindow("IEFrame", vbNullString)
        If hWin <> 0 Then
            Msgbox "IE's handle: " & hWin
        Else
            Msgbox "IE not found"
        End If
    
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Location
    Singapore
    Posts
    24
    Thanks it works. I found a description of the FindWindow function, it wrtoe:

    The FindWindow function retrieves the handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows.


    What do you mean by top-level window??? In my case i got the handle of the IE behind the application. When i open another IE and minimize all the IE windows(now i got 2 IE opened), i got the handle of the new IE window that i opened.

    Thanks

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    When it says top level window, it is referring to the main window of an application. The main window will contain many windows inside it. These are child windows. They dont have to actually be "windows" though. Buttons, list boxes, etc. are all considered child windows. To search for the handles of these objects, read up on the findwindowex routine. To get the handle of All Open IE windows, Use FindwindowEx also. Plug the handle of the Last found IE into i t, and it will return the next handle. Keep this up for any number of ie windows open.

    example code:
    dim Parent as long
    dim LastWindowFound as long
    Parent = 0 '0 is the desktop, which is parent to top-lev. LastWindowFound = 0
    do
    hWin = FindWindowEx(Parent, LastWindowFound, "IEFrame", vbNullString)
    If hWin <> 0 Then
    Msgbox "IE's handle: " & hWin
    Else
    Msgbox "IE not found"
    End If
    LastWindowFound = hWin
    loop until hWin = 0
    Last edited by Lord Orwell; Feb 10th, 2001 at 11:01 PM.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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