我用下面的代码中获得flash控件的句柄实现屏蔽FLASH菜单的功能,但是为什么当窗体上存在有两个以上的Flash控件的时候却只屏蔽其中一个FLASH菜单呢???望哪位高人指点。Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Const GWL_WNDPROC = (-4)
Private Const WM_RBUTTONDOWN = &H204Private Type POINTAPI
    x As Long
    y As Long
End Type
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Public ret As Long'SetWindowLong 的回调函数, 利用 Msg 拦截消息
Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If Msg = WM_RBUTTONDOWN Then Exit Function
    WindowProc = CallWindowProc(ret, hwnd, Msg, wParam, lParam)
End Function
Private Sub Form_Load()
Dim hFlash As Long
hFlash = FindWindowEx(picMain(7).hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString)
ret = SetWindowLong(hFlash, GWL_WNDPROC, AddressOf WindowProc)
End Sub

解决方案 »

  1.   

    先提示一下,你只运行一次  FindWindowEx 当然只找到一个Flash窗口,你得再用  FindWindowEx 找一次,得把已经找到的窗口句柄当作  FindWindowEx 的第二个参数
      

  2.   

    在Form_Load()里再写两句Private Sub Form_Load()
        Dim hFlash As Long
        hFlash = FindWindowEx(picMain(7).hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString)
        ret = SetWindowLong(hFlash, GWL_WNDPROC, AddressOf WindowProc)    hFlash = FindWindowEx(picMain(7).hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString)
        ret = SetWindowLong(hFlash, GWL_WNDPROC, AddressOf WindowProc)
    End Sub
      

  3.   

    //我用下面的代码中获得flash控件的句柄实现屏蔽FLASH菜单的功能,但是为什么当窗体上存在有两个以上的Flash控件的时候却只屏蔽其中一个FLASH菜单呢???望哪位高人指点。你的代码只对一个控件进行了子类处理,当然只能屏蔽一个
      

  4.   

    Option Explicit
    'MacromediaFlashPlayerActiveX
    Private Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)
    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 Const PM_NOREMOVE = &H0
    Private Const PM_NOYIELD = &H2
    Private Const PM_REMOVE = &H1
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    Private Type Msg
        hwnd As Long
        Message As Long
        wParam As Long
        lParam As Long
        time As Long
        pt As POINTAPI
    End Type
    Private Const WM_RBUTTONDBLCLK = &H206
    Private Const WM_RBUTTONDOWN = &H204
    Private Const WM_RBUTTONUP = &H205Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
    Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
    Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
    Private Declare Function WaitMessage Lib "user32" () As Long
    Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
    Private bCancel As BooleanPrivate Sub ProcessMessages()
        Dim Message As Msg
        'loop until bCancel is set to True
        Do While Not bCancel
            '等待一个消息
            WaitMessage
            If PeekMessage(Message, 0, 0, 0, PM_REMOVE) Then
                 Select Case Message.Message
                 '过滤掉关于右键操作的三个消息WM_RBUTTONDOWN 、WM_RBUTTONUP、WM_RBUTTONDBLCLK
                 Case WM_RBUTTONDOWN, WM_RBUTTONUP, WM_RBUTTONDBLCLK
                    If mGetclassName(Message.hwnd) = "MacromediaFlashPlayerActiveX" Then
                        MsgBox "Webbrowser控件的WM_RBUTTONDOWN消息已经被屏蔽"
                    Else
                        TranslateMessage Message
                        DispatchMessage Message
                    End If
                 Case Else
                    TranslateMessage Message
                    DispatchMessage Message
                 End Select
            End If
            '将控制权交还给系统,否则将陷入死循环
            DoEvents
        Loop
    End Sub
    Private Sub Form_Load()
        Dim Ret As Long
        bCancel = False
        Show
        ProcessMessages
        
    End SubPrivate Sub Form_Unload(Cancel As Integer)
    bCancel = True
    End SubPrivate Function mGetclassName(ByVal WinWnd As Long) As String
       Dim lpClassName As String, RetVal As Long
       lpClassName = Space(256)
        RetVal = GetClassName(WinWnd, lpClassName, 256)
        mGetclassName = Left$(lpClassName, RetVal)
    End Function
      

  5.   

    '这是窗体代码,你把代码中的 Me.hwnd 替换成 Flash 控件所在的窗口的句柄就行。这个窗口中可以放任意个数的 Flash 控件
    Option ExplicitPrivate Sub Form_Load()
        Dim ret As Long
        Dim i As Long
        
        ret = FindWindowEx(Me.hwnd, 0&, "MacromediaFlashPlayerActiveX", vbNullString)
        If ret <> 0 Then
            ReDim hFlash(0)
            Do While ret <> 0
                ReDim Preserve hFlash(UBound(hFlash) + 1)
                hFlash(UBound(hFlash)) = ret
                ret = FindWindowEx(Me.hwnd, hFlash(UBound(hFlash)), "MacromediaFlashPlayerActiveX", vbNullString)
            Loop
        End If
        If UBound(hFlash) > 1 Then
            ReDim prevWndProc(UBound(hFlash))
            For i = 1 To UBound(hFlash)
                prevWndProc(i) = GetWindowLong(hFlash(i), GWL_WNDPROC)
                SetWindowLong hFlash(i), GWL_WNDPROC, AddressOf WndProc
            Next i
        End If
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        Dim i As Long
        If UBound(hFlash) > 1 Then
            For i = 1 To UBound(hFlash)
                SetWindowLong hFlash(i), GWL_WNDPROC, prevWndProc(i)
            Next i
        End IfEnd Sub
    '模块代码
    Option ExplicitPublic Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public 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
    Public Const GWL_WNDPROC = (-4)
    Public hFlash() As Long
    Public prevWndProc() As LongPrivate Const WM_RBUTTONDOWN = &H204
    Private Const WM_RBUTTONUP = &H205Public Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Dim i As Long
        For i = 1 To UBound(hFlash)
            If hFlash(i) = hwnd Then
                If Msg = WM_RBUTTONDOWN Or Msg = WM_RBUTTONUP Then
                    Exit Function
                Else
                    WndProc = CallWindowProc(prevWndProc(i), hFlash(i), Msg, wParam, lParam)
                    Exit For
                End If
            End If
        Next i
    End Function