May 2nd, 2002, 04:59 AM
#1
Thread Starter
Addicted Member
Locating windows question
Ok, I know how to find windows. How can I get the number of Windows that have the same name/class? For example, I want to count all the windows that are labeled "Hi" and then put that number in a variable. Here's what I have so far to find all the Winamp apps that are open. Please help me finish the code! Thanks
VB Code:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
hWndWinAMP = FindWindow("Winamp v1.x", vbNullString)
VB6, VB.NET, C#, SQL, XML, ADO.NET, ASP.NET, HTML.
MCP & A+ Certified. Looking for a job in the Seattle, WA area.
May 2nd, 2002, 05:19 AM
#2
Frenzied Member
You can do this with the EventVB.dll thus:
VB Code:
Option Explicit
Dim WithEvents vbLink As EventVB.ApiFunctions
Private Sub Form_Load()
Set vbLink = New ApiFunctions
Dim wndThis As ApiWindow
Dim lFound As Long
For Each wndThis In vbLink.System.TopLevelWindows
If wndThis.WindowText = "Hi" Then
lFound = lFound + 1
End If
Next wndThis
MsgBox "Found " & lFound & " windows caption = Hi "
End Sub
HTH,
Duncan
May 2nd, 2002, 05:38 AM
#3
Thread Starter
Addicted Member
Thanks for the code. What if I have the class of the window, not the name. Here's an example:
VB Code:
FindWindow("Winamp v1.x", vbNullString)
Can the code you gave me above be altered to find windows by the class name?
VB6, VB.NET, C#, SQL, XML, ADO.NET, ASP.NET, HTML.
MCP & A+ Certified. Looking for a job in the Seattle, WA area.
May 2nd, 2002, 06:00 AM
#4
Member
This seems very familiar to something I needed awhile ago try this:
Check the attached module:
This code makes an array of al windows' captions, and then searches for a window ending with "- Tester", and closes it.
It all starts with this code below(on a form):
VB Code:
Function GetCaptions()
Dim vCaps, strArray As Variant
Dim lIndex As Long
Dim iArraySize As Integer
vCaps = GetAllCaptions()
iArraySize = UBound(vCaps)
strArray = MakeStrArray(vCaps, iArraySize)
If TesterIsRunning(strArray, iArraySize) Then
If CloseExtApp(strActiveTester) Then
MsgBox "Program is ready to continue", vbInformation, "Tester closed"
Else
MsgBox "Automatic shutdown of Tester failed" & vbCrLf _
& "Please close Tester, then try again", vbCritical, "Tester not closed"
End
End If
End If
--------------------------------------------------------------------------------
for (int i = 0;i < y3k; i++)
{
MakeMeSmarter (andMoreTolerant);
}
May 2nd, 2002, 06:07 AM
#5
Member
Oops forgot to add the needed module:
Take a look at the attached module for more info on using the code above.
Attached Files
for (int i = 0;i < y3k; i++)
{
MakeMeSmarter (andMoreTolerant);
}
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