Results 1 to 14 of 14

Thread: IE child windows

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    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

  2. #2
    Tygur
    Guest
    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)

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    Do you know how to find all the child windows? Not controls? Would I have to use find window? Thanks
    Matt

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    No, FindWindow won't find any child windows, but you can use GetClassName to filter all windows whose classname is "IEFrame".

  5. #5
    Megatron
    Guest
    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.

  6. #6

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    Right but shoulden't it retrieve the children of the IE window?
    Matt

  7. #7
    Megatron
    Guest
    It should...What does it output for you? (I don't have VB on this machine, so I cannot test it).

  8. #8

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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

  9. #9
    Megatron
    Guest
    Many of them do not have names (titles). If you use GetClassName, you could find the class names (rather than the window names).

  10. #10
    Megatron
    Guest
    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

  11. #11

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    Works great, thanks alot megatron!
    Matt

  12. #12

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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

  13. #13
    Megatron
    Guest
    Post the WM_CLOSE, WM_DESTROY and WM_NCDESTROY messages as well (in that order). WM_QUIT should be last.

  14. #14
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    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
  •  



Click Here to Expand Forum to Full Width