谢谢~!!!

解决方案 »

  1.   

    根据另一个程序的标题或类名,用findwindow进行查找:
    【VB声明】
      Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long【别名】
      FindWindowA【说明】
      寻找窗口列表中第一个符合指定条件的顶级窗口(在vb里使用:FindWindow最常见的一个用途是获得ThunderRTMain类的隐藏窗口的句柄;该类是所有运行中vb执行程序的一部分。获得句柄后,可用api函数GetWindowText取得这个窗口的名称;该名也是应用程序的标题) 【返回值】
      Long,找到窗口的句柄。如未找到相符窗口,则返回零。会设置GetLastError 【备注】
      很少要求同时按类与窗口名搜索。为向自己不准备参数传递一个零,最简便的办法是传递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"【参数表】
      lpClassName ----  String,指向包含了窗口类名的空中止(C语言)字串的指针;或设为零,表示接收任何类  lpWindowName ---  String,指向包含了窗口文本(或标签)的空中止(C语言)字串的指针;或设为零,表示接收任何窗口标题例子:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Const SW_SHOWNORMAL = 1
    Const WM_CLOSE = &H10
    Const gcClassnameMSWord = "OpusApp"
    Const gcClassnameMSExcel = "XLMAIN"
    Const gcClassnameMSIExplorer = "IEFrame"
    Const gcClassnameMSVBasic = "wndclass_desked_gsk"
    Const gcClassnameNotePad = "Notepad"
    Const gcClassnameMyVBApp = "ThunderForm"
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
        'Ask for a Window title
        Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
        'Search the window
        WinWnd = FindWindow(vbNullString, Ret)
        If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
        'Show the window
        ShowWindow WinWnd, SW_SHOWNORMAL
        'Create a buffer
        lpClassName = Space(256)
        'retrieve the class name
        RetVal = GetClassName(WinWnd, lpClassName, 256)
        'Show the classname
        MsgBox "Classname: " + Left$(lpClassName, RetVal)
        'Post a message to the window to close itself
        PostMessage WinWnd, WM_CLOSE, 0&, 0&
    End Sub