你要的资料:GetClassName VB声明 
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long 
说明 
为指定的窗口取得类名 
返回值 
Long,以字节数表示的类名长度;排除最后的空中止字符。零表示出错。会设置GetLastError 
参数表 
参数 类型及说明 
hwnd Long,欲获得类名的那个窗口的句柄 
lpClassName String,随同类名载入的缓冲区。预先至少必须分配nMaxCount+1个字符 
nMaxCount Long,由lpClassName提供的缓冲区长度 
FindWindowEx VB声明 
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 
说明 
在窗口列表中寻找与指定条件相符的第一个子窗口 
返回值 
Long,找到的窗口的句柄。如未找到相符窗口,则返回零。会设置GetLastError 
参数表 
参数 类型及说明 
hWnd1 Long,在其中查找子的父窗口。如设为零,表示使用桌面窗口(通常说的顶级窗口都被认为是桌面的子窗口,所以也会对它们进行查找) 
hWnd2 Long,从这个窗口后开始查找。这样便可利用对FindWindowEx的多次调用找到符合条件的所有子窗口。如设为零,表示从第一个子窗口开始搜索 
lpsz1 String,欲搜索的窗体名。零表示忽略 
lpsz2 String,欲搜索的类名。零表示忽略 

解决方案 »

  1.   

    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
      

  2.   

    Const WS_CHILD = &H40000000
    Const WM_LBUTTONDOWN = &H201
    Const WM_LBUTTONUP = &H202
    Const SW_HIDE = 0
    Const SW_NORMAL = 1
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    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
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    Dim tWnd As Long, bWnd As Long, ncWnd As Long
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim R As RECT
        'Get the taskbar's window handle
        tWnd = FindWindow("Shell_TrayWnd", vbNullString)
        'Get the start-button's window handle
        bWnd = FindWindowEx(tWnd, ByVal 0&, "BUTTON", vbNullString)
        'Get the start button's position
        GetWindowRect bWnd, R
        'Create a new button
        ncWnd = CreateWindowEx(ByVal 0&, "BUTTON", "Hello !", WS_CHILD, 0, 0, R.Right - R.Left, R.Bottom - R.Top, tWnd, ByVal 0&, App.hInstance, ByVal 0&)
        'Show our button
        ShowWindow ncWnd, SW_NORMAL
        'Hide the start button
        ShowWindow bWnd, SW_HIDE
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        'show the start button
        ShowWindow bWnd, SW_NORMAL
        'destroy our button
        DestroyWindow ncWnd
    End Sub
      

  3.   

    Option Explicit
    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 LongPrivate Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
    Private Const GW_HWNDFIRST = 0 '为一个源子窗口寻找第一个兄弟(同级)窗口,或寻找第一个顶级窗口
    Private Const GW_HWNDLAST = 1  '为一个源子窗口寻找最后一个兄弟(同级)窗口,或寻找最后一个顶级窗口
    Private Const GW_HWNDNEXT = 2  '为源窗口寻找下一个兄弟窗口
    Private Const GW_HWNDPREV = 3  '为源窗口寻找前一个兄弟窗口
    Private Const GW_OWNER = 4     '寻找窗口的所有者
    Private Const GW_CHILD = 5     '寻找源窗口的第一个子窗口Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongPublic Function GetClassNameStr(hWnd As Long) As String
        Dim TempLng As Long
        Dim TempStr As String
        Dim Rc As Long
        
        TempLng = 260
        TempStr = Space(TempLng)
        
        Rc = GetClassName(hWnd, TempStr, TempLng)
        
        GetClassNameStr = StrConv(LeftB$(StrConv(TempStr, vbFromUnicode), Rc), vbUnicode)
        
    End FunctionPublic Function FindWnd(ByVal PhWnd As Long, ClassStr As String) As Long
        Dim TemphWnd As Long
        
        TemphWnd = GetWindow(PhWnd, GW_CHILD)
        Do
            If GetClassNameStr(TemphWnd) = ClassStr Then Exit Do
        Loop While TemphWnd = GetWindow(PhWnd, GW_HWNDNEXT)
        
        FindWnd = TemphWnd
        
    End FunctionPrivate Sub Form_Load()
        Dim TemphWnd As Long
        
        TemphWnd = FindWnd(Me.hWnd, "MarcomediaFlashPlayerActiveX")
        MsgBox TemphWnd & vbCrLf & GetClassNameStr(TemphWnd)
        
    End Sub