Saturday, December 20, 2014
    Search Web Link
Search Software
API Home » Window » EnumChildWindows


Category: Window
Hits: 16308 Rating: EnumChildWindows has been rated 2.93 by  694 users (2.93) votes 694
Rate: 1-star  2-stars  3-stars  4-stars  5-stars
E-mail this API to friend E-mail this Code to a friend  save Bookmark this VB API Function
API Explanation
EnumChildWindows enumerates and provides handles to all of the child windows of a given window. This function will also enumerate any children of the child windows. Each time a child window is located, the function passes that handle to a program-defined callback function (see below). The function continues doing so until all child windows have been enumerated, or until the process has been aborted. Along with a window's handle, the function also passes a program-defined value to the callback function. The function returns 1 if completed successfully, or 0 if an error occured.

Parameter Information
Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As _
Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Associated Program-Defined Callback Function:

Function EnumChildProc (ByVal hwnd As Long, ByVal lParam As Long) As Long
' program-defined code goes here
End Function

A handle to the parent window to enumerate the child windows of.
A handle to the program-defined callback function. Visual Basic users must use the AddressOf operator to determine the
function's handle.
An additional value to pass to the program-defined callback function.

EnumChildProc is a program-defined callback function which EnumChildWindows calls each time it locates a child window.
The callback function can do whatever it wishes with the handle provided -- the implementation is up to the programmer. If the
function returns 0, EnumChildWindows will prematurely cancel the enumeration process. If the function returns a non-zero value,
EnumChildWindows will continue to enumerate windows until all of them have been enumerated. (Note: the program doesn't
have to call this function EnumChildProc, but it is the standard name given to it.)

A handle to the window which EnumChildWindows has just found.
Whatever value was specified for EnumChildWindows's lParam.

' Display the title bar text of all children of window MDIForm1. This
' task is given to the callback function, which will receive each handle individually.

' *** Place this code in a module. This is the callback function. ***
' This function displays the title bar text of the window identified by hwnd.
Public Function EnumChildProc (ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim slength As Long, wintext As String ' title bar text length and buffer
Dim retval As Long ' return value
Static winnum As Integer ' counter keeps track of how many windows have been enumerated

winnum = winnum + 1 ' one more window enumerated....
slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text
buffer = Space(slength) ' make room in the buffer
retval = GetWindowText(hwnd, buffer, slength) ' get title bar text
Debug.Print "Window #"; winnum; " : "; ' display number of enumerated window
Debug.Print Left(buffer, slength - 1) ' display title bar text of enumerated window

EnumChildProc = 1 ' return value of 1 means continue enumeration
End Function

' *** Place this code wherever you want to enumerate the windows. ***
Dim retval As Long ' return value

' Use the above callback function to list all of the enumerated windows. Note that lParam is
' set to 0 because we don't need to pass any additional information to the function.
retval = EnumChildWindows(MDIForm1.hWnd, AddressOf EnumChildProc, 0)

Copyright © 2000 - 2013 Ex-designz. All rights reserved. Website Developed By Dexter Zafra of
Link to us | Advertisement | Contact us | Privacy Policy | Terms of use | Accessibility