|
-
Feb 2nd, 2004, 09:05 PM
#1
Thread Starter
Frenzied Member
[VB] FindWindowLike
Option Explicit
Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Public Const GW_HWNDNEXT = 2
Public Const GW_CHILD = 5
'********************************************
'*Give it part of the window text your looking for
'*it will give you the hWnd
'*usefull for windows that text is like "[project] - microsoft visual basic [design]"
'*usage:
'*Msgbox FindWindowLike("visual basic")
'*Returns 0 if not found
'*******************************************
Function FindWindowLike(strPartOfCaption As String) As Long
Dim hWnd As Long
Dim strCurrentWindowText As String
Dim r As Integer
hWnd = GetForegroundWindow
Do Until hWnd = 0
strCurrentWindowText = Space$(255)
r = GetWindowText(hWnd, strCurrentWindowText, 255)
strCurrentWindowText = Left$(strCurrentWindowText, r)
'hWnd = GetWindow(hWnd, GW_CHILD)
If InStr(1, LCase(strCurrentWindowText), LCase(strPartOfCaption)) <> 0 Then GoTo Found
hWnd = GetWindow(hWnd, GW_HWNDNEXT)
Loop
Exit Function
Found:
FindWindowLike = hWnd
End Function
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
|