Link to home
Start Free TrialLog in
Avatar of Jon-Leach
Jon-Leach

asked on

How do I find a windowclass by using the first 9 letters of the caption?

In VB.NET I want to locate a window class by using the first 9 letters of the caption, I am looking at using the FindWindow API is there a better way or easier way of doing this?
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

FindWindow() requires an EXACT match so you'd have to iterate over EVERY single window and check for your criteria...
Avatar of Jon-Leach
Jon-Leach

ASKER

ok, so then once I find the full caption how can I pull it out and comapare? It is there a Function I can use?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks let me try this.
Very helpful was able to modify the code with little effort to do what I wanted in my code.
*FYI, I think Bob (TheLearnedOne) is the original author of the WindowsEnumerator() class I used:
https://www.experts-exchange.com/questions/23357525/get-all-Window-Handles-hWND-associated-with-a-Process.html

He's posted it in many other PAQs and I picked it up and made minor mods to it...
I got quick question I moved this section below in it's own function to be called upon by a timer and now I get an error aw note declared? I looked high and low and can;t figure out why it not declaring it.
Dim we As New WindowsEnumerator
        Dim DialogWindows As List(Of ApiWindow) = we.GetTopLevelWindows()
        For Each aw In DialogWindows
            If aw.Text.ToLower.StartsWith("abcdefghi") Then
               Label1.text = "Found"
                ' ... do something in here ...

                ' ... possibly use "aw.Handle" ? ....
                ' ... or "aw.ClassName" ? ...

                Exit For
            End If
        Next

Open in new window

You can change:

    For Each aw In DialogWindows

To:

    For Each aw As ApiWindow In DialogWindows
That worked thanks, man was that a duh momnet on my part. Thanks for the help and the other link too.