如何得到同类型同标题的两个顶层窗口句柄(同类型同标题,但各有一个不同的子窗口)???闷闷不乐ing……

解决方案 »

  1.   

    先去得这两个窗体的句柄,在用GetTopWindow取得子窗体的句柄。比较判断
    GetTopWindow :
    Public Declare Function GetTopWindow Lib "user32" Alias "GetTopWindow" (ByVal hwnd As Long) As Long
    搜索内部窗口列表,寻找隶属于指定窗口的头一个窗口的句柄。
      

  2.   

    用EnumWindows和GetWindowText 取的窗口标题比较应该可以吧
      

  3.   

    EnumChildWindows 为指定的父窗口枚举子窗口
    EnumWindows 枚举窗口列表中的所有父窗口 
    'in a form
    Private Sub Form_Load()
        Me.AutoRedraw = True
        EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0&
    End Sub
    'in a module
    Declare Function GetDesktopWindow Lib "user32" () As Long
    Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam 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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Dim sSave As String
        'Get the windowtext length
        sSave = Space$(GetWindowTextLength(hwnd) + 1)
        'get the window text
        GetWindowText hwnd, sSave, Len(sSave)
        'remove the last Chr$(0)
        sSave = Left$(sSave, Len(sSave) - 1)
        If sSave <> "" Then Form1.Print sSave
        'continue enumeration
        EnumChildProc = 1
    End Function
      

  4.   

    用EnumWindows(获取窗口句柄后可以用getclassname获得窗口类名。用getwindowtext获得窗口标题,然后根据类名和标题确定你要查找的窗口,并将找到的句柄保存到数组里,以方便以后使用)和EnumChildWindows(先遍历数组中的每个元素,然后用这个函数判断枚举子窗口(你确定是子窗口吗?)最后确定窗口句柄)