標籤:dha protect 菜單 滑鼠 pre 禁用 nothing imessage overflow
出處:http://stackoverflow.com/questions/41781647/disabling-the-axwebbrowser-context-menu-vb-net
通過底層訊息禁止滑鼠右鍵訊息傳送到AxWebBrowser控制項上,從而禁止了右鍵菜單。
以此類推,應該任何控制項都可以用此方法禁止指定訊息的傳遞。。
Public Class Form1 Implements IMessageFilter Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage Const WM_RBUTTONDOWN As Integer = &H204 Const WM_RBUTTONDBLCLK As Integer = &H206 ‘ check that the message is WM_RBUTTONDOWN Or WM_RBUTTONDBLCLK ‘ verify AxWebBrowser1 is not null ‘ verify the target is AxWebBrowser1 Return (m.Msg = WM_RBUTTONDOWN OrElse m.Msg = WM_RBUTTONDBLCLK) AndAlso (AxWebBrowser1 IsNot Nothing) AndAlso (AxWebBrowser1 Is Control.FromChildHandle(m.HWnd)) End Function Protected Overrides Sub OnActivated(e As EventArgs) MyBase.OnActivated(e) ‘ Filter is application wide, activate filter with form Application.AddMessageFilter(Me) End Sub Protected Overrides Sub OnDeactivate(e As EventArgs) MyBase.OnDeactivate(e) ‘ Filter is application wide, remove when form not active Application.RemoveMessageFilter(Me) End SubEnd Class
禁用AxWebBrowser右鍵菜單