Results 1 to 4 of 4

Thread: enumerate child windows

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    43

    enumerate child windows

    is there a way to enumerate child windows in VBA. I have a method to do it in VB6 but it appears that VBA (Access) does not support the AddressOf operator. I have a login window for a program and have to search for the text entry boxes. They are not in sequential order and both have edit for the class

  2. #2
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Assuming you can use other APIs, you could do something like this (and I don't know about Acess myself, so this may not work, but it's a way to do it without enumeration):
    VB Code:
    1. 'the needed function
    2. Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpszClassName As String, ByVal lpszCaption As String) As Long
    3.  
    4. 'for this to work you either need to know the window handle of the login window, or the classname of it if not
    5. 'assuming first you know the window handle (which I'll call hWnd)
    6. Dim hWndFind As Long
    7. 'get the first child window with the class "Edit" (a textbox to VB)
    8. hWndFind = FindWindowEx(hWnd, 0, "Edit", vbNullString)
    9. 'go through the rest of the children
    10. Do Until hWndFind = 0
    11.    'if you get here, hWndFind is the handle to an edit control, so do something with it
    12.  
    13.    'look for the next edit control
    14.    hWndFind = FindWindowEx(hWnd, hWndFind, "Edit", vbNullString)
    15. Loop
    16.  
    17.  
    18. 'now if you don't know hWnd, you'll have to do this, which requires you to know the name of the dialog's class
    19. Dim hWnd As Long
    20. hWnd = FindWindowEx(0, 0, "dialogclassname", vbNullString)
    21. 'then you can use the above process
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  3. #3
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

    Here you go

    Here is some funky code that will work with VBA. This example enumerates the child windows of a running version of calculator, so start up calculator and see it list the hwnds of all the child windows in the debug window.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
    4. Private Const GW_CHILD = 5
    5. Private Const GW_HWNDNEXT = 2
    6.  
    7. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    8.  
    9. Private Sub Command1_Click()
    10.  
    11.  Dim hwndParent&, hwndChild&
    12.  
    13.  hwndParent = FindWindow(vbNullString, "Calculator")
    14.  If hwndParent Then
    15.    
    16.     hwndChild = GetWindow(hwndParent, GW_CHILD)  'Find Child    
    17.     Do While hwndChild
    18.    
    19.         Debug.Print hwndChild
    20.  
    21.         hwndChild = GetWindow(hwndChild, GW_HWNDNEXT) 'Continue Enumeration
    22.     Loop
    23.  
    24.  End If
    25.  
    26. End Sub
    Last edited by Nucleus; Sep 12th, 2001 at 12:12 AM.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    43
    Thanx guys your solutions worked

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