主题:鼠标右键问题
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 "欢迎加入"
Case WM_RBUTTONUP
'MsgBox "欢迎加入"
Case WM_RBUTTONDBLCLK
MsgBox "欢迎加入"
'对于其它消息则放行
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
WebBrowser1.Navigate "http://www.***.com"
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
上面是禁止WebBrowser右键的,但是他连Tab(也就是键盘Q左边那个)也禁止了,是不是上面代码的问题?大家帮帮忙哦~
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 "欢迎加入"
Case WM_RBUTTONUP
'MsgBox "欢迎加入"
Case WM_RBUTTONDBLCLK
MsgBox "欢迎加入"
'对于其它消息则放行
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
WebBrowser1.Navigate "http://www.***.com"
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
上面是禁止WebBrowser右键的,但是他连Tab(也就是键盘Q左边那个)也禁止了,是不是上面代码的问题?大家帮帮忙哦~