Results 1 to 6 of 6

Thread: Child Windows

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    59

    Talking

    To Find the Handle of a Window you use the FindWindow API. But what would one use to find the handle of a Child Window?. Can somebody please Give me an example of finding a Child Window. Thanx

  2. #2
    Guest
    Use FindWindowEx. Next example will get the hWnd of the TextBox inside Notepad.
    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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Sub Command1_Click()
    
        Dim hParent As Long
        Dim hChild As Long
        
        'Get the handle of Notepad
        hParent = FindWindow("Notepad", vbNullString)
        'Get the handle of the TextBox inside Notepad
        hChild = FindWindowEx(hParent, 0&, "Edit", vbNullString)
        
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    59
    Thank you Megatron you have been very helpful. Can you find a child window by its Class or by it't Title? is there an API for that?

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    59
    For Example: FindChildByTitle(hwnd,"")
    or: FindChildByClass(hwnd,"")...

  5. #5
    Guest
    Yes, FindWindowEx allows for both. The last argument specifies the Window title and the 2nd last argument specifies the ClassName.

    For example, if you wanted to find a Button, you would use
    Code:
    hChild = FindWindowEx(hParent, 0&, "Button", vbNullString)
    If you wanted to find a window that has the text of "Hello!" you would use.
    Code:
    hChild = FindWindowEx(hParent, 0&, vbNullString, "Hello!")

  6. #6
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    Somebody goofed when they put together the winapi.txt file from the API Viewer

    I found the following declaration for findwindowex much more descriptive:
    Code:
    Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String) As Long

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