|
-
Feb 2nd, 2009, 06:53 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] how would you uses FindWindow like this?
how would I do a instr for this, the caption changes but at the beginning there also this "Timery" so it how would I find it i tried
lhWnd = InStr(FindWindow, vbNullString, "Timery")
Code:
Dim lhWnd As Long
Do
lhWnd = FindWindow(vbNullString, "Timery")
If lhWnd Then
MsgBox "it here"
End If
Loop While lhWnd
Last edited by newprogram; Feb 2nd, 2009 at 07:04 PM.
Live life to the fullest!!
-
Feb 2nd, 2009, 07:08 PM
#2
Re: how would you uses FindWindow like this?
I don't think you can do that with FindWindow. How about using EnumWindows API?
-
Feb 2nd, 2009, 07:13 PM
#3
Re: how would you uses FindWindow like this?
Here's a way to use the "*" character as a wild card to get handles of windows by passing a partial title and class name.
Code:
Option Explicit
Private WinHwnd(512) As Long
Private WindCnt As Integer
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Function FindWindowLike(ByVal hWndStart As Long, WindowText As String, Classname As String) As Long
Dim hwnd As Long
Dim sWindowText As String
Dim sClassname As String
Dim r As Long
Static level As Integer
If level = 0 Then
If hWndStart = 0 Then hWndStart = GetDesktopWindow()
End If
level = level + 1
hwnd = GetWindow(hWndStart, GW_CHILD)
Do Until hwnd = 0
Call FindWindowLike(hwnd, WindowText, Classname)
sWindowText = Space$(255)
r = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, r)
sClassname = Space$(255)
r = GetClassName(hwnd, sClassname, 255)
sClassname = Left(sClassname, r)
If (sWindowText Like WindowText) And (sClassname Like Classname) Then
WinHwnd(WindCnt) = hwnd
WindCnt = WindCnt + 1
End If
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
level = level - 1
End Function
Private Sub Command1_Click()
Dim i As Integer
Erase WinHwnd()
WindCnt = 0 ' reset counter
' use "*" as wild card before and after classname and title as needed.
' strings are case sensitve!
' find all open programs with title bar that includes "VBForums"
FindWindowLike 0, "*VBForums*", "*" ' start hwnd, titlebar, classname
For i = 0 To WindCnt - 1
Debug.Print WinHwnd(i) ' show all handles found
Next i
End Sub
Last edited by Edgemeal; Feb 2nd, 2009 at 07:20 PM.
Reason: updated
-
Feb 2nd, 2009, 07:14 PM
#4
Re: how would you uses FindWindow like this?
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Feb 2nd, 2009, 07:21 PM
#5
Thread Starter
Fanatic Member
Re: how would you uses FindWindow like this?
thank you . Edgemeal that work great!!
Live life to the fullest!!
-
Feb 2nd, 2009, 07:33 PM
#6
Re: [RESOLVED] how would you uses FindWindow like this?
How about this?
Code:
Option Explicit
Private Sub Form_Load()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
In a module
Code:
Option Explicit
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
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
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sWindowText As String
Dim Ret As Long
Ret = GetWindowTextLength(hwnd)
sWindowText = Space(Ret)
GetWindowText hwnd, sWindowText, Ret + 1
If Ret > 0 Then
If sWindowText Like "Projec*" Then
Debug.Print sWindowText
End If
End If
EnumWindowsProc = True
End Function
-
Feb 2nd, 2009, 11:37 PM
#7
Thread Starter
Fanatic Member
Re: [RESOLVED] how would you uses FindWindow like this?
that work even better thank you!!
 Originally Posted by dee-u
How about this?
Code:
Option Explicit
Private Sub Form_Load()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
In a module
Code:
Option Explicit
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
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
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sWindowText As String
Dim Ret As Long
Ret = GetWindowTextLength(hwnd)
sWindowText = Space(Ret)
GetWindowText hwnd, sWindowText, Ret + 1
If Ret > 0 Then
If sWindowText Like "Projec*" Then
Debug.Print sWindowText
End If
End If
EnumWindowsProc = True
End Function
Live life to the fullest!!
-
Feb 2nd, 2009, 11:44 PM
#8
Re: [RESOLVED] how would you uses FindWindow like this?
 Originally Posted by newprogram
that work even better thank you!!
But you can't enter a classname, so it does have some drawbacks.
(dee-u hint hint )
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
|