Results 1 to 4 of 4

Thread: Find window with wildcards?

  1. #1

    Thread Starter
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Can I find a window with the FindWindow API with wildcards?

    Like "* - Netscape"?

    Thanks
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Nope, but here's a Function I wrote a few months ago to do it:

    In a Module:
    Code:
    Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
    Private Declare Function GetTopWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Const GW_HWNDNEXT = 2
    
    Public Function FindWindowWild(ByVal lHWnd As Long, ByVal sTitle) As Long
        Dim sString As String * 255
        Dim sFound As String
        If lHWnd = 0 Then lHWnd = GetTopWindow(0)
        Do
            lHWnd = GetNextWindow(lHWnd, GW_HWNDNEXT)
            Call GetWindowText(lHWnd, sString, 255)
            sFound = Left(sString, InStr(sString, Chr(0)) - 1)
        Loop While lHWnd And Not (LCase(sFound) Like LCase(sTitle))
        FindWindowWild = lHWnd
    End Function
    Example:
    Code:
    Private lFindHwnd As Long
    
    Private Sub cmdFindFirst_Click()
        Dim sString As String * 255
        lFindHwnd = FindWindowWild(0, Text1)
        Call GetWindowText(lFindHwnd, sString, 255)
        Text2 = Left(sString, InStr(sString, Chr(0)) - 1)
    End Sub
    
    Private Sub cmdFindNext_Click()
        Dim sString As String * 255
        lFindHwnd = FindWindowWild(lFindHwnd, Text1)
        Call GetWindowText(lFindHwnd, sString, 255)
        Text2 = Left(sString, InStr(sString, Chr(0)) - 1)
    End Sub

  3. #3
    Lively Member
    Join Date
    Jan 2000
    Posts
    95

    Talking findwindowex too??

    will that work for FindwindowEx too?

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    It doesn't use any of the FindWindow API's, it's a replacement which incorporates Wildcards.


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