用gettopwindow还是其他

解决方案 »

  1.   

    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Longa=findwindows ("类名","窗口名")
      

  2.   

    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPrivate Sub Timer1_Timer()
        Dim Ret     As Long
        Dim MyStr   As String
        
        Ret = GetForegroundWindow()
        
        MyStr = String(100, Chr$(0))
        GetWindowText Ret, MyStr, 100
        MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
        Debug.Print MyStr
    End Sub
      

  3.   

    不能用findwindow函数,事先不知道caption的GetForegroundWindow()仅仅是得到活动窗体,不是得到顶层窗体
      

  4.   

    Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Public Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    EnumWindows可以枚举给定窗口的顶级窗口,EnumChildWindows可以枚举给定窗口的子窗口