|
-
Jul 4th, 2001, 01:49 PM
#1
Thread Starter
New Member
FindWindow with multiple possibilities
I want to use the FindWindow API in conjunction with previnstance to find the handle of the previous instance of my app. However, the caption on my form is variable depending on what it is doing and there may be more than one window with the classname "ThunderRT6FormDC". So, my questions are:
Is there any way to get FindWindow to return an array with the hwnd's to all applicable windows so as i can find the correct one from there (i.e. by checking its icon or something)?
OR
Can I search for just part of a form's caption? This way i could keep part of the caption (for example: the first four letters) constant and use FindWindow to search for that?
Hope that makes some sense
Thanx
-
Jul 4th, 2001, 02:40 PM
#2
Add to a Module
VB 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
Length = GetWindowTextLength(hwnd) + 1
If Length > 1 Then
sName = Space(Length)
GetWindowText hwnd, sName, Length
sName = Left(sName, Length - 1)
'Use the Like operator to search with wildcards
If sName Like "*My Window Title*" And hWnd <> Form1.hWnd Then
MsgBox "The handle is: " & hwnd
End If
End If
EnumWindowsProc = 1
End Function
Usage:
VB Code:
EnumWindows AddressOf EnumWindowsProc, 0
-
Jul 4th, 2001, 02:57 PM
#3
Thread Starter
New Member
Thanx Megatron, looks like just what i need
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|