请问高手:如何获得Flash动画控件ShockwaveFlash1的句柄hWnd,以便在Flash动画上响应鼠标事件。

解决方案 »

  1.   

    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 GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As LongPrivate Sub Command1_Click()
        If WriteOnFlashWindow("你好!我是绿豆!") Then
            MsgBox "成功了~~"
        Else
            MsgBox "失败了~~"
        End If
    End SubFunction FindFlashWindow(ByVal hWndParent As Long) As Long
        FindFlashWindow = FindWindowEx(hWndParent, 0&, "MacromediaFlashPlayerActiveX", "")
    End FunctionFunction WriteOnFlashWindow(ByVal sWord As String) As Boolean
        On Error Resume Next
        Dim hWndFlash As Long
        Dim hDCFlash As Long
        
        sWord = "Hello World!"
        hWndFlash = FindFlashWindow(Form1.hwnd)
        If hWndFlash Then
            hDCFlash = GetDC(hWndFlash)
            If hDCFlash Then
                TextOut hDCFlash, 0, 0, sWord, Len(sWord)
                ReleaseDC hWndFlash, hDCFlash
            End If
        End If
        WriteOnFlashWindow = (Err.Number = 0)
    End Function