Results 1 to 2 of 2

Thread: Findwindow to find imperfectwindow

  1. #1

    Thread Starter
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402

    Question

    How do you use Findwindow to find a window that you only know a portion of the title or classname?


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  2. #2
    Guest
    You can use WnumWindows to enumerate all of the open windows, then use the Like operator (with wildcards) to find the title.

    Add to a Module
    Code:
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    
    Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Dim Length As Long
        Dim sName As String
        Dim Temp As String
        Static iCount As Integer
        
        iCount = iCount + 1
        Length = GetWindowTextLength(hwnd) + 1
        
        If Length > 1 Then
          sName = Space(Length)
          GetWindowText hwnd, sName, Length
          sName = Left(sName, Length - 1)
          'Replace "Portion of Title" with the portion of your window name. Remember to keep the astrikes at the end and beginning
          If sName 
    Like "*Portion of title*" Then MsgBox "The handle is: " & hwnd
        End If
        
        EnumWindowsProc = 1
    End Function
    Usage: (Add to a CommandButon)
    Code:
    EnumWindows AddressOf EnumWindowsProc, 0

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