|
-
May 1st, 2001, 06:14 PM
#1
Thread Starter
Hyperactive Member
IE child windows
Code:
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
Matt 
-
May 1st, 2001, 08:32 PM
#2
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)
-
May 2nd, 2001, 02:39 PM
#3
Thread Starter
Hyperactive Member
Do you know how to find all the child windows? Not controls? Would I have to use find window? Thanks
Matt 
-
May 2nd, 2001, 02:52 PM
#4
PowerPoster
No, FindWindow won't find any child windows, but you can use GetClassName to filter all windows whose classname is "IEFrame".
-
May 2nd, 2001, 05:07 PM
#5
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.
-
May 2nd, 2001, 05:15 PM
#6
Thread Starter
Hyperactive Member
Right but shoulden't it retrieve the children of the IE window?
Matt 
-
May 2nd, 2001, 05:23 PM
#7
It should...What does it output for you? (I don't have VB on this machine, so I cannot test it).
-
May 2nd, 2001, 05:39 PM
#8
Thread Starter
Hyperactive Member
Well it prints that there is like 15 sometimes 27 children enumerated but
Debug.Print Left(buffer, length - 1)
does not print there titles.
Matt 
-
May 2nd, 2001, 06:22 PM
#9
Many of them do not have names (titles). If you use GetClassName, you could find the class names (rather than the window names).
-
May 2nd, 2001, 06:26 PM
#10
Okay, try this (for the class names).
Code:
Dim sClass As String
sClass = Space(255)
iLength = GetClassName(hwnd, sClass, 255)
sClass = Left(sClass, iLength)
Debug.Print sClass
-
May 3rd, 2001, 05:14 PM
#11
Thread Starter
Hyperactive Member
Works great, thanks alot megatron!
Matt 
-
May 6th, 2001, 03:26 PM
#12
Thread Starter
Hyperactive Member
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
Matt 
-
May 6th, 2001, 04:25 PM
#13
Post the WM_CLOSE, WM_DESTROY and WM_NCDESTROY messages as well (in that order). WM_QUIT should be last.
-
May 6th, 2001, 10:01 PM
#14
PowerPoster
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|