Results 1 to 4 of 4

Thread: FindWindowEx when we don't know exactly what the caption is

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    FindWindowEx when we don't know exactly what the caption is

    How to do so?

    Also is there a function where we can enumerate all child of a window?

    I use FindWindowEx but sometimes it "skip" a window.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: FindWindowEx when we don't know exactly what the caption is

    Is this question still valid?. You have another thread that is very similar.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Re: FindWindowEx when we don't know exactly what the caption is

    Code:
    Option Explicit
    
    Public Const WM_GETTEXT As Long = &HD&
    Public Const WM_GETTEXTLENGTH As Long = &HE&
    
    Public Declare Function EnumChildWindows Lib "User32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Public Declare Function EnumWindows Lib "User32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Public Declare Function SendMessageA Lib "User32.dll" (ByVal hwnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
    
    
    Public Function GetWindowText(WindowH As Long) As String
    Dim Length As Long
    Dim Text As String
    
    Text = String$(SendMessageA(WindowH, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1, vbNullChar)
    Length = SendMessageA(WindowH, WM_GETTEXT, ByVal Len(Text), ByVal Text)
    GetWindowText = Left$(Text, Length)
    End Function
    
    Public Function HandleChildWindows(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Debug.Print GetWindowText(hwnd)
    
    HandleChildWindows = CLng(True)
    End Function
    
    Public Function HandleWindows(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Debug.Print GetWindowText(hwnd)
    
    EnumChildWindows hwnd, AddressOf HandleChildWindows, CLng(0)
    
    HandleWindows = CLng(True)
    End Function
    
    Public Sub Main()
    EnumWindows AddressOf HandleWindows, CLng(0)
    End Sub
    Replace the "Debug.Print" lines with code that checks whether the text is the text your program is looking for in a window.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: FindWindowEx when we don't know exactly what the caption is

    I figured that out.

    Enumwindow is one way.

    Another is to use findwindowex with vbnullstring

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