Results 1 to 3 of 3

Thread: FindWindow Api

  1. #1

    Thread Starter
    New Member Sulo's Avatar
    Join Date
    Oct 1999
    Posts
    12

    Post

    I need to find the handles of four windows that have the
    same Classname and same Window Caption. Is there a way I
    can make a loop with the Findwindow Api to find all four handles?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    You can use the FindWindowEx API, it has a Parameter which specifies which Window Handle to Start Looking From, so you could write a Function to Return an Array of all Windows Matching the Class and/or Caption criteria, ie.
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    Public Function GetHwnds(ByVal Class As String, ByVal Caption As String) As Variant
        Dim lHwnd() As Long
        Dim lCount As Long
        Dim lHandle As Long
        ReDim lHwnd(0)
        Do
            lHandle = FindWindowEx(0, lHandle, Class, Caption)
            If lHandle Then
                ReDim Preserve lHwnd(lCount)
                lHwnd(lCount) = lHandle
                lCount = lCount + 1
            End If
        Loop While lHandle
        GetHwnds = lHwnd
    End Function
    Example of Usage:
    Code:
    Private Sub Command1_Click()
        Dim lHwnd As Variant
        Dim iIndex As Long
        lHwnd = GetHwnds("NotePad", vbNullString)
        For iIndex = 0 To UBound(lHwnd)
            If lHwnd(iIndex) Then
                'Do Whatever with the Window Handle Here..
                Debug.Print lHwnd(iIndex)
            End If
        Next
    End Sub

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Or you can use EnumWindows API to enumerate all running windows. If you're intersted, then check out Code Snippet I've posted for a similar question.

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