Results 1 to 9 of 9

Thread: How To Get MDI Child Window Handle

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    60

    How To Get MDI Child Window Handle

    Hi,
    I have an application running say "TestApp" which has two child windows opened say Window1 and Window2. Now I need to write a program, which can give me all the Opened Child Windows Handle Number and Its Window Title. How To do it. I tried using GetTopWindows(), EnumChildWindows(), FindWindowEx() functions. But I am Unsuccessful. I am able to get the Main application Title and Handle Number using the Findwindow() Function. Can any one help me...Thanks in Advance...

  2. #2
    Megatron
    Guest
    Use EnumChildWindows. Here is the simplest form:

    Add to a Module
    Code:
    Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    
    Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Debug.Print hwnd
    End Function
    Usage:
    Code:
    EnumChildWindows hwnd, AddressOf EnumChildProc, 0

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    How abt the FindWindowEx API?

  4. #4
    Megatron
    Guest
    No, FindWindowEx will get the first child window, then you need to use GetWindow to retrieve the other windows.

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Thanks, Meg

  6. #6
    Megatron
    Guest
    Sorry, it should be GetNextWindow (It's even simpler than GetWindow).

  7. #7
    Megatron
    Guest
    Here's a simple example.
    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
    Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
    
    Private Sub Command1_Click()
    
        Dim hChild As Long
        
        hChild = FindWindowEx(Me.hwnd, 0, vbNullString, vbNullString)
        Do While hChild <> 0
            DoEvents
            Debug.Print hChild
            hChild = GetNextWindow(hChild, 2)
        Loop
        
    End Sub

  8. #8
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Actually you can just use FindWindowEx to loop through all children. Here is an example:
    Code:
        Dim lngHWnd As Long
        
        lngHWnd = FindWindowEx(Form1.hWnd, 0, vbNullString, vbNullString)
        
        Do Until lngHWnd = 0
            Debug.Print lngHWnd
            lngHWnd = FindWindowEx(Form1.hWnd, lngHWnd, vbNullString, vbNullString)
        Loop
    Notice second parameter? This will tell function to look for the next child window after the hWnd passed as a second parameter.

  9. #9
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Surge

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