FindWindow VB声明 
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 
说明 
寻找窗口列表中第一个符合指定条件的顶级窗口(在vb里使用:FindWindow最常见的一个用途是获得ThunderRTMain类的隐藏窗口的句柄;该类是所有运行中vb执行程序的一部分。获得句柄后,可用api函数GetWindowText取得这个窗口的名称;该名也是应用程序的标题) 
返回值 
Long,找到窗口的句柄。如未找到相符窗口,则返回零。会设置GetLastError 
参数表 
参数 类型及说明 
lpClassName String,指向包含了窗口类名的空中止(C语言)字串的指针;或设为零,表示接收任何类 
lpWindowName String,指向包含了窗口文本(或标签)的空中止(C语言)字串的指针;或设为零,表示接收任何窗口标题 
注解 
很少要求同时按类与窗口名搜索。为向自己不准备参数传递一个零,最简便的办法是传递vbNullString常数
 
示例 
Dim hw&, cnt&
Dim rttitle As String * 256
hw& = FindWindow("ThunderRT5Main", vbNullString) ' ThunderRTMain under VB4
cnt = GetWindowText(hw&, rttitle, 255)
MsgBox Left$(rttitle, cnt), 0, "RTMain title" 

解决方案 »

  1.   

    EnumWindows VB声明 
    Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) 
    说明 
    枚举窗口列表中的所有父窗口(顶级和被所有窗口) 
    返回值 
    Long,非零表示成功,零表示失败 
    参数表 
    参数 类型及说明 
    lpEnumFunc Long,指向为每个子窗口都调用的一个函数的指针。用AddressOf运算符获得函数在标准模式下的地址 
    lParam Long,在枚举期间,传递给dwcbkd32.ocx定制控件之EnumWindows事件的值。这个值的含义是由程序员规定的 'EnumWindows
    'Add this code to a form
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'Set the form's graphics mode to persistent
        Me.AutoRedraw = True
        'call the Enumwindows-function
        EnumWindows AddressOf EnumWindowsProc, ByVal 0&
    End Sub
    'Add this code to a module
    Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
    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 EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
        Dim sSave As String, Ret As Long
        Ret = GetWindowTextLength(hwnd)
        sSave = Space(Ret)
        GetWindowText hwnd, sSave, Ret + 1
        Form1.Print Str$(hwnd) + " " + sSave
        'continue enumeration
        EnumWindowsProc = True
    End Function