Results 1 to 5 of 5

Thread: Locating windows question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Location
    Seattle, WA USA
    Posts
    216

    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:
    1. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. 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.

  2. #2
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    You can do this with the EventVB.dll thus:

    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents vbLink As EventVB.ApiFunctions
    4.  
    5. Private Sub Form_Load()
    6.  
    7. Set vbLink = New ApiFunctions
    8.  
    9. Dim wndThis As ApiWindow
    10. Dim lFound As Long
    11.  
    12. For Each wndThis In vbLink.System.TopLevelWindows
    13.    If wndThis.WindowText = "Hi" Then
    14.       lFound = lFound + 1
    15.    End If
    16. Next wndThis
    17.  
    18. MsgBox "Found " & lFound & " windows caption = Hi "
    19.  
    20. End Sub

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Location
    Seattle, WA USA
    Posts
    216
    Thanks for the code. What if I have the class of the window, not the name. Here's an example:
    VB Code:
    1. 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.

  4. #4
    Member imj75's Avatar
    Join Date
    Aug 2000
    Location
    South Africa,Pretoria
    Posts
    51
    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:
    1. Function GetCaptions()
    2. Dim vCaps, strArray As Variant
    3. Dim lIndex As Long
    4. Dim iArraySize As Integer
    5.    
    6.     vCaps = GetAllCaptions()
    7.     iArraySize = UBound(vCaps)
    8.     strArray = MakeStrArray(vCaps, iArraySize)
    9.     If TesterIsRunning(strArray, iArraySize) Then
    10.         If CloseExtApp(strActiveTester) Then
    11.             MsgBox "Program is ready to continue", vbInformation, "Tester closed"
    12.         Else
    13.             MsgBox "Automatic shutdown of Tester failed" & vbCrLf _
    14.             & "Please close Tester, then try again", vbCritical, "Tester not closed"
    15.             End
    16.         End If
    17.     End If
    18.  
    19. --------------------------------------------------------------------------------
    for (int i = 0;i < y3k; i++)
    {
    MakeMeSmarter (andMoreTolerant);
    }

  5. #5
    Member imj75's Avatar
    Join Date
    Aug 2000
    Location
    South Africa,Pretoria
    Posts
    51
    Oops forgot to add the needed module:
    Take a look at the attached module for more info on using the code above.
    Attached Files 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
  •  



Click Here to Expand Forum to Full Width