窗体:
Dim WebhWnd&
Public Sub FindWebPage(ByVal hParentWnd As Long)
Dim strClassName As String * 30
Dim hTempWnd As Long
hTempWnd = GetWindow(hParentWnd, GW_CHILD)
Do While (hTempWnd <> 0)
strClassName = ""
GetClassName hTempWnd, strClassName, 30
If left(strClassName, Len("Internet Explorer_Server")) = "Internet Explorer_Server" Then
WebhWnd = hTempWnd
Exit Sub
End If
FindWebPage hTempWnd
hTempWnd = GetWindow(hTempWnd, GW_HWNDNEXT)
Loop
End Sub
Private Sub Command1_Click()
FindWebPage Me.hwnd
HookWind WebhWnd
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate ""
End Sub
模块:
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmdAs Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByValhwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA"(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByValwParam As Long, ByVal lParam As Long) As Long
Public Const GW_CHILD As Long = 5
Public Const GW_HWNDNEXT As Long = 2
Private Const GWL_WNDPROC As Long = -4
Private Const WM_RBUTTONDOWN As Long = &H204
Private Const WM_RBUTTONUP As Long = &H205
Private Const WM_RBUTTONDBLCLK As Long = &H206
Private lpPrevWndFunc As Long
Public Function HookWind(ByVal hwnd As Long) As Long
lpPrevWndFunc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Function
Public Function UnHookWind(ByVal hwnd As Long) As Long
SetWindowLong hwnd, GWL_WNDPROC, lpPrevWndFunc
End Function
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParamAs Long, ByVal lParam As Long) As Long
Select Case uMsg
Case WM_RBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONDBLCLK
WindowProc = 1
Exit Function
Case Else
WindowProc = CallWindowProc(lpPrevWndFunc, hwnd, uMsg, wParam, lParam)
End Select
End Function
这个方法比引用法好多了。。
或者干脆直接在网页源码里面加入屏蔽右键的代码:
<script>
function stop(){
return false;
}
document.oncontextmenu=stop;
script>
阅读(261) | 评论(0) | 转发(0) |