PDA

Click to See Complete Forum and Search --> : IE child windows


MPrestonf12
May 1st, 2001, 06:14 PM
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
Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Private Const WM_QUIT = &H12
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Public Sub findwin()
Dim hwnd As Long
Dim retval As Long

hwnd = FindWindowEx(0, 0, "IEFrame", vbNullString)

If hwnd <> 0 Then
retval = EnumChildWindows(hwnd, AddressOf EnumChildProc, 0)
End If

End Sub

Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Static count As Integer
Dim length As Long, retval As Long
Dim buffer As String

count = count + 1
length = GetWindowTextLength(hwnd) + 1
buffer = Space(length)
retval = GetWindowText(hwnd, buffer, length)
Debug.Print "Window "; count; " : ";
Debug.Print Left(buffer, length - 1)
EnumChildProc = 1
End Function



Shoulden't this code enumerate all of IE's cjild windows. When I run it it says there are like 27 windows open yet all I have open is a parent window IE and a popup inside it. I don't know what the problem is. Thanks

Tygur
May 1st, 2001, 08:32 PM
You have to realize that a control is also a window. EnumChildWindows is working exactly as it's supposed to. Did you ever try this on a form?

An IE window has many controls on it. (ComboBox, Text Box, Toolbar, etc)

MPrestonf12
May 2nd, 2001, 02:39 PM
Do you know how to find all the child windows? Not controls? Would I have to use find window? Thanks

amitabh
May 2nd, 2001, 02:52 PM
No, FindWindow won't find any child windows, but you can use GetClassName to filter all windows whose classname is "IEFrame".

Megatron
May 2nd, 2001, 05:07 PM
EnumChildWindows will enumerate the windows, but keep in mind that each window has their own child windows as well. This function will not retrieve the grand children and great grand children of IE.

MPrestonf12
May 2nd, 2001, 05:15 PM
Right but shoulden't it retrieve the children of the IE window?

Megatron
May 2nd, 2001, 05:23 PM
It should...What does it output for you? (I don't have VB on this machine, so I cannot test it).

MPrestonf12
May 2nd, 2001, 05:39 PM
Well it prints that there is like 15 sometimes 27 children enumerated but

Debug.Print Left(buffer, length - 1)

does not print there titles.

Megatron
May 2nd, 2001, 06:22 PM
Many of them do not have names (titles). If you use GetClassName, you could find the class names (rather than the window names).

Megatron
May 2nd, 2001, 06:26 PM
Okay, try this (for the class names).

Dim sClass As String

sClass = Space(255)
iLength = GetClassName(hwnd, sClass, 255)
sClass = Left(sClass, iLength)

Debug.Print sClass

MPrestonf12
May 3rd, 2001, 05:14 PM
Works great, thanks alot megatron!

MPrestonf12
May 6th, 2001, 03:26 PM
When I post a quit message to the window all it does is destroy its contents but the actual window is still there. How do I close the window entirly? Thanks

Megatron
May 6th, 2001, 04:25 PM
Post the WM_CLOSE, WM_DESTROY and WM_NCDESTROY messages as well (in that order). WM_QUIT should be last.

amitabh
May 6th, 2001, 10:01 PM
Megatron, is this order applicable for all windows. Every time I need to kill a window, I need to send these messages in the same order?