Chinaunix首页 | 论坛 | 博客
  • 博客访问: 195791
  • 博文数量: 106
  • 博客积分: 3810
  • 博客等级: 中校
  • 技术积分: 1007
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 13:35
文章分类

全部博文(106)

文章存档

2014年(17)

2011年(5)

2010年(75)

2009年(9)

我的朋友

分类: Windows平台

2014-03-20 10:04:26

窗体:

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 LongByVal wCmdAs LongAs Long
Public Declare Function 
GetClassName Lib "user32" Alias "GetClassNameA" (ByValhwnd As LongByVal lpClassName As StringByVal nMaxCount As LongAs Long
Private Declare Function 
SetWindowLong Lib "user32" Alias "SetWindowLongA"(ByVal hwnd As LongByVal nIndex As LongByVal dwNewLong As LongAs Long
Private Declare Function 
CallWindowProc Lib "user32" Alias "CallWindowProcA"(ByVal lpPrevWndFunc As LongByVal hwnd As LongByVal Msg As LongByValwParam As LongByVal lParam As LongAs 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 LongAs Long
    
lpPrevWndFunc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Function
                                                                    
Public Function 
UnHookWind(ByVal hwnd As LongAs Long
    
SetWindowLong hwnd, GWL_WNDPROC, lpPrevWndFunc
End Function
                                                                    
Public Function 
WindowProc(ByVal hwnd As LongByVal uMsg As LongByVal wParamAs LongByVal lParam As LongAs 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) |
给主人留下些什么吧!~~