PDA

Click to See Complete Forum and Search --> : Findwindow to find imperfectwindow


Microbasic
Mar 15th, 2001, 12:03 PM
How do you use Findwindow to find a window that you only know a portion of the title or classname?

Mar 15th, 2001, 12:07 PM
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

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)

EnumWindows AddressOf EnumWindowsProc, 0