none
如何屏蔽ShockwaveFlash的右键,同时左键有效? RRS feed

  • 问题

  •  

    如题,可以把menu属性设为false,但还有“关于”,可以用一个容器把它装起来,再把容器的Enabled设为false,但左键也没效了。
    2008年6月5日 1:27

答案

  •  

    Code Snippet

    Public Delegate Function NewWndProc(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

     

     

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function CallWindowProc(ByVal wndProc As IntPtr, ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

        End Function
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal wndproc As NewWndProc) As IntPtr

        End Function
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As IntPtr) As IntPtr

        End Function
        Public Const GWL_WNDPROC As Integer = -4
        Private Const WM_RBUTTONDOWN = &H204

     

     

    Code Snippet

    Private wpr As NewWndProc
        Private oldWndProc As IntPtr
        Public Sub Hook()
            wpr = New NewWndProc(AddressOf Me.WindowProc)
            oldWndProc = SetWindowLong(AxShockwaveFlash1.Handle, GWL_WNDPROC, wpr)
        End Sub
        Public Sub UnHook()
            SetWindowLong(AxShockwaveFlash1.Handle, GWL_WNDPROC, oldWndProc)
        End Sub

        Private Function WindowProc(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

            If (msg = WM_RBUTTONDOWN) Then     ' 屏蔽右键
                WindowProc = 0
                Exit Function
            End If

            WindowProc = CallWindowProc(oldWndProc, hWnd, msg, _
                                       wParam, lParam)

        End Function

     
    Code Snippet
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Hook()
        End Sub
    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            UnHook()
        End Sub

     

     

     
     
     
    2008年6月5日 3:19
    版主

全部回复

  •  

    Code Snippet

    Public Delegate Function NewWndProc(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

     

     

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function CallWindowProc(ByVal wndProc As IntPtr, ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

        End Function
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal wndproc As NewWndProc) As IntPtr

        End Function
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As IntPtr) As IntPtr

        End Function
        Public Const GWL_WNDPROC As Integer = -4
        Private Const WM_RBUTTONDOWN = &H204

     

     

    Code Snippet

    Private wpr As NewWndProc
        Private oldWndProc As IntPtr
        Public Sub Hook()
            wpr = New NewWndProc(AddressOf Me.WindowProc)
            oldWndProc = SetWindowLong(AxShockwaveFlash1.Handle, GWL_WNDPROC, wpr)
        End Sub
        Public Sub UnHook()
            SetWindowLong(AxShockwaveFlash1.Handle, GWL_WNDPROC, oldWndProc)
        End Sub

        Private Function WindowProc(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

            If (msg = WM_RBUTTONDOWN) Then     ' 屏蔽右键
                WindowProc = 0
                Exit Function
            End If

            WindowProc = CallWindowProc(oldWndProc, hWnd, msg, _
                                       wParam, lParam)

        End Function

     
    Code Snippet
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Hook()
        End Sub
    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            UnHook()
        End Sub

     

     

     
     
     
    2008年6月5日 3:19
    版主
  •  

    谢谢!
    2008年6月7日 5:56