Results 1 to 13 of 13

Thread: Classnames & Findwindowex

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Posts
    71

    Question

    Is there a way to find out the class name of active window & then use this class name & findwindowex api to obtain the handles of the child windows of the active window ?

  2. #2
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    If it is just the active window you are interested in, then Declare Function GetActiveWindow& Lib "user32" ()
    dim hwnd as long
    hwnd = GetActiveWindow()
    will give you the handle of the active window. Use this instead of the class name in the findwindowex function. It will accept either.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Posts
    71

    Question

    Hi Orwell , my code is shown below whereby i only used
    the caption to find the child handles using findwindowex api . But the returned value is 0 . Can you guide me why this is so ?

    fish = GetForegroundWindow()

    x = GetActiveWindowTitle(True)
    hWnd_MD = FindWindowEx(0, 0, vbNullString, x)
    ' in module
    Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Public sClassname As String
    Public r As String
    Public fish As Long
    Public j As Long
    Public 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
    Public Declare Function GetForegroundWindow Lib "user32.dll" () As Long



    ' Returns the title of the active window.
    ' if GetParent = true then the parent window is
    ' returned.
    Public Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String



    fish = GetForegroundWindow


    If ReturnParent Then
    Do While fish <> 0
    j = fish
    fish = GetParent(fish)
    Loop

    fish = j
    End If

    GetActiveWindowTitle = GetWindowTitle(fish)
    End Function
    Public Function GetWindowTitle(ByVal hwnd As Long) As String
    Dim l As Long
    Dim s As String

    l = GetWindowTextLength(hwnd)
    s = Space(l + 1)

    GetWindowText hwnd, s, l + 1

    GetWindowTitle = Left$(s, l)
    End Function

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    fish = GetForegroundWindow()
    minnow = findwindowex(fish, 0, vbnullstring, vbnullstring)
    will store the handle to a child window in minnow.
    I am not sure why you were using the caption, but in your code sample, it is not necessary.
    This code will find all of the child windows:
    fish = GetForegroundWindow()
    minnow = 0
    do
    minnow = findwindowex(fish, minnow, vbnullstring, vbnullstring)
    debug.print minnow
    loop until minnow = 0
    Last edited by Lord Orwell; Feb 20th, 2001 at 04:25 AM.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Lord Orwell

    Can you really use the hWnd instead of the classname? Thanks for that - tip of the day!! I never saw that documented anywhere - cool - that makes my life a lot easier.
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  6. #6
    Guest
    Why not just use the EnumChildWindows API function.

  7. #7
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    [edited to correct my errors )
    How about a code sample? I have never needed that api call, and would like to see an example of it used.
    Last edited by Lord Orwell; Feb 21st, 2001 at 12:16 AM.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Posts
    71

    Question

    Hi Orwell , my code which i want to save all the child handles to a dynamic array cannot work saying subscript out of range , can you help me ?

    Public lHwnd() As long
    Public iCount As Integer

    iCount = 0
    ReDim Preserve lHwnd(iCount)
    fish = GetForegroundWindow()
    hWnd_MD = FindWindowEx(fish, 0, vbNullString, vbNullString)
    Do
    hWnd_MD = FindWindowEx(fish, hWnd_MD, vbNullString, vbNullString)
    lHwnd(iCount) = hWnd_MD
    iCount = iCount + 1
    Loop Until hWnd_MD = 0

    ------------------------------------------------------------------------
    Originally posted by Lord Orwell
    fish = GetForegroundWindow()
    minnow = findwindowex(fish, 0, vbnullstring, vbnullstring)
    will store the handle to a child window in minnow.
    I am not sure why you were using the caption, but in your code sample, it is not necessary.
    This code will find all of the child windows:
    fish = GetForegroundWindow()
    minnow = 0
    do
    minnow = findwindowex(fish, minnow, vbnullstring, vbnullstring)
    debug.print minnow
    loop until minnow = 0

  9. #9
    Guest
    Here's an example of using EnumChildWindows.

    Add to a Module.
    Code:
    Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Public lHwnd() As Long
    Public iCount As Integer
    
    Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        iCount = iCount + 1
        ReDim Preserve lHwnd(iCount)
        lHwnd(iCount) = hwnd
        EnumChildProc = 1
    End Function
    Add to a Form
    Code:
    Private Sub Command1_Click()
        EnumChildWindows hwnd, AddressOf EnumChildProc, 0
        
        For i = 0 To UBound(lHwnd)
            Debug.Print lHwnd(i)
        Next i
    End Sub

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    Megatron thanks for the code sample. It answers a question or two i had

    Eng70640 The problem with your code is you are redimming the size of the array to zero. I can see what you were trying to do. You should have put the redim inside of the loop.
    Working code(i hope ):
    Public lHwnd(0) As long
    Public iCount As Integer

    iCount = 0
    ReDim Preserve lHwnd(iCount)
    fish = GetForegroundWindow()
    hWnd_MD = FindWindowEx(fish, 0, vbNullString, vbNullString)
    Do
    iCount = iCount + 1
    hWnd_MD = FindWindowEx(fish, hWnd_MD,
    vbNullString, vbNullString)
    if hWnd_MD > 0 then
    Redim Preserve lHwnd(iCount)
    lHwnd(iCount) = hWnd_MD
    end if
    Loop Until hWnd_MD = 0
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Posts
    71

    Question

    But when i put the redim inside of the loop , there is error by the vb compiler .

    Originally posted by Lord Orwell
    Megatron thanks for the code sample. It answers a question or two i had

    Eng70640 The problem with your code is you are redimming the size of the array to zero. I can see what you were trying to do. You should have put the redim inside of the loop.
    Working code(i hope ):
    Public lHwnd(0) As long
    Public iCount As Integer

    iCount = 0
    ReDim Preserve lHwnd(iCount)
    fish = GetForegroundWindow()
    hWnd_MD = FindWindowEx(fish, 0, vbNullString, vbNullString)
    Do
    iCount = iCount + 1
    hWnd_MD = FindWindowEx(fish, hWnd_MD,
    vbNullString, vbNullString)
    if hWnd_MD > 0 then
    Redim Preserve lHwnd(iCount)
    lHwnd(iCount) = hWnd_MD
    end if
    Loop Until hWnd_MD = 0

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Posts
    71

    Question

    Moreover , i have deleted the line 'icount = 0' & there is still error .

  13. #13
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    heh i declared the array incorrectly.
    To be able to resize an array, lHwnd has to be declared
    like this:
    dim lHwnd() as long
    not like this:
    dim lHwnd(0) as long
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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