Results 1 to 4 of 4

Thread: FindWindowEx to get MDI Child handle?

  1. #1

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391

    Question FindWindowEx to get MDI Child handle?

    Can anyone explain to me how to use the FindWindowEx function to get the handle of a mdi child?

    I used
    Code:
    WinWnd = FindWindow(vbNullString, "My App Title")
    to get the handle of the parent window. But when I try

    Code:
        bWnd = FindWindowEx(WinWnd, ByVal 0&, vbNullString, "My Child Title")
    bWnd is always 0...

    "MyChildTitle 1" is the only child form under the parent. I've tried with two children but it still wont pick up any of them...any ideas?

    Thanks.
    Last edited by brenaaro; Apr 2nd, 2002 at 04:04 PM.

  2. #2
    jim mcnamara
    Guest
    FindWindowEx only finds parent windows.

    After you have the handle to the parent MDI window then call EnumChildWindows

    MDIhWnd is the handle of the parent
    Code:
    'in a form
    Private Function GetChild(MDIhWnd as long) as long
        Dim MDIhnd as long
        Me.AutoRedraw = True
        EnumChildWindows MDIhWnd, AddressOf EnumChildProc, ByVal 0&
    End Function
    
    'in a module
    Declare Function GetDesktopWindow Lib "user32" () As Long
    Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Dim sSave As String
        'Get the windowtext length
        sSave = Space$(GetWindowTextLength(hwnd) + 1)
        'get the window text
        GetWindowText hwnd, sSave, Len(sSave)
        'remove the last Chr$(0)
        sSave = Left$(sSave, Len(sSave) - 1)
        If sSave <> "" Then Form1.Print sSave
        'continue enumeration
        EnumChildProc = 1
    End Function

  3. #3

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Thanks Jim, I had seen the EnumFunction in the API guide but I wasn't sure it was what I needed since the decription of FindWindowEx said it searched child windows.

    Anyways, it worked, I got the handle, thanks a bunch =)

  4. #4
    Registered User
    Join Date
    Mar 2019
    Posts
    2

    Re: FindWindowEx to get MDI Child handle?

    Quote Originally Posted by brenaaro View Post
    Thanks Jim, I had seen the EnumFunction in the API guide but I wasn't sure it was what I needed since the decription of FindWindowEx said it searched child windows.

    Anyways, it worked, I got the handle, thanks a bunch =)
    Hi Thread Starter ! Have you Finished this code ? Please Please share me , i'm stucking with the same problem !

    Please show me your code

    Thanks you so much !

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