Click to See Complete Forum and Search --> : How to get the handle of a window thats behind another window
heavenhell
Feb 7th, 2001, 07:37 PM
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
Use the FindWindow API function.
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
heavenhell
Feb 7th, 2001, 09:02 PM
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
Lord Orwell
Feb 10th, 2001, 09:48 PM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.