-
Sep 11th, 2001, 09:21 PM
#1
Thread Starter
Member
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
-
Sep 11th, 2001, 11:03 PM
#2
Fanatic Member
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:
'the needed function
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
'for this to work you either need to know the window handle of the login window, or the classname of it if not
'assuming first you know the window handle (which I'll call hWnd)
Dim hWndFind As Long
'get the first child window with the class "Edit" (a textbox to VB)
hWndFind = FindWindowEx(hWnd, 0, "Edit", vbNullString)
'go through the rest of the children
Do Until hWndFind = 0
'if you get here, hWndFind is the handle to an edit control, so do something with it
'look for the next edit control
hWndFind = FindWindowEx(hWnd, hWndFind, "Edit", vbNullString)
Loop
'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
Dim hWnd As Long
hWnd = FindWindowEx(0, 0, "dialogclassname", vbNullString)
'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
-
Sep 12th, 2001, 12:00 AM
#3
Registered User
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:
Option Explicit
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Private Sub Command1_Click()
Dim hwndParent&, hwndChild&
hwndParent = FindWindow(vbNullString, "Calculator")
If hwndParent Then
hwndChild = GetWindow(hwndParent, GW_CHILD) 'Find Child
Do While hwndChild
Debug.Print hwndChild
hwndChild = GetWindow(hwndChild, GW_HWNDNEXT) 'Continue Enumeration
Loop
End If
End Sub
Last edited by Nucleus; Sep 12th, 2001 at 12:12 AM.
-
Sep 13th, 2001, 08:12 AM
#4
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|