屏蔽webbrowser控件右键的一种方法

简介: 原文:屏蔽webbrowser控件右键的一种方法Option ExplicitPrivate Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)Priva...
原文: 屏蔽webbrowser控件右键的一种方法

Option Explicit
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 = &H205
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 Boolean
Private webHwnd As Long '窗体中webbrowser控件的句柄
Private Sub ProcessMessages()
    Dim Message As Msg
    'loop until bCancel is set to True
    Do While Not bCancel
        '等待一个消息
        WaitMessage
        '检查webbrowser控件及其子窗口的所有消息
        If PeekMessage(Message, webHwnd, 0, 0, PM_REMOVE) Then
             Select Case Message.Message
             '过滤掉关于右键操作的三个消息WM_RBUTTONDOWN 、WM_RBUTTONUP、WM_RBUTTONDBLCLK
             Case WM_RBUTTONDOWN
                MsgBox "Webbrowser控件的WM_RBUTTONDOWN消息已经被屏蔽"
             Case WM_RBUTTONUP
                MsgBox "Webbrowser控件的WM_RBUTTONUP消息已经被屏蔽"
             Case WM_RBUTTONDBLCLK
                MsgBox "Webbrowser控件的WM_RBUTTONDBLCLK消息已经被屏蔽"
             '对于其它消息则放行
             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
    webHwnd = FindWindowEx(Me.hwnd, 0, "Shell Embedding", vbNullString)
    If webHwnd > 0 Then
        'ProcessMessages
    End If
End Sub


Private Sub Form_Unload(Cancel As Integer)
bCancel = True
End Sub

 遗憾的是,程序有时候会发生进程阻塞,导致拦截消息失败

 

目录
相关文章
|
C++ Windows
C++ Windows窗口程序:子窗口控件之按钮类button
C++ Windows窗口程序:子窗口控件之按钮类button
882 0
|
C++
基于MFC实现选项卡控件练习
基于MFC实现选项卡控件练习
72 0
基于MFC实现选项卡控件练习
在C#中设置窗体最前,并且如果不关掉这个窗体,就不能操作其余的控件
窗口名 新窗口名 = new 窗口名();新窗口名.ShowDialog();
479 0
|
测试技术
MFC中为菜单或按钮添加快捷键功能
1、新建一快捷键资源,ACCELERATOR,关联相应的ID号,下图所示中,其中,第一个ID为自定义快捷键ID,按CTRL+R,此时响应该ID以应的消息响应函数, 第二个ID为菜单ID,此时按CTRL+V,调出ID_NETWORK_PING菜单对应的响应函数。
1377 0
|
C#
C#引用CefSharp并屏蔽鼠标右键和禁止拖动放置事件
原文:C#引用CefSharp并屏蔽鼠标右键和禁止拖动放置事件 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013564470/article/details/78339957 ...
4249 0
|
安全
OCX控件避免弹出安全警告的类
1.要加一个头文件:         #include 2.在控件头文件中加入: 1 DECLARE_INTERFACE_MAP()2 BEGIN_INTERFACE_PART(ObjectSafety, IObjectSafety)3 STDMETHOD(GetInter...
917 0