PDA

Click to See Complete Forum and Search --> : Disabling Mouse button


sunithi
Aug 6th, 2001, 06:25 AM
Can I disable the right mouse button when it is moved over the Webbrowser control? My intention is to prevent the user from cutting and pasting the contents in the webbrowser and also to prevent from seeing the HTML source.

please help. I am desperate.

Sunithi

Matthew Gates
Aug 6th, 2001, 11:39 AM
Try this:


'Author: Yonatan
'Origin: http://www.vbforums.com
'Purpose: Disable Right Click in Webbrowser
'Version: VB5+


'Module Code:

Option Explicit

Private Declare Function CallWindowProc Lib "user32" _
Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As _
Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam 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 IsWindow Lib "user32" (ByVal hWnd As Long) _
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 GWL_WNDPROC = (-4)
Public Const WM_MOUSEACTIVATE = &H21
Public Const MA_ACTIVATEANDEAT = 2
Private lpfnPreviousWindowProcedure As Long
Private m_lhWnd As Long

Private Function WindowProcedure(ByVal hWnd As Long, ByVal uMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As Long

If (uMsg = WM_MOUSEACTIVATE) And (lParam = &H2040001) Then ' Don't ask about the lParam...
WindowProcedure = MA_ACTIVATEANDEAT
Exit Function
End If
WindowProcedure = CallWindowProc(lpfnPreviousWindowProcedure, _
hWnd, uMsg, wParam, lParam)

End Function

Public Sub Hook(ByVal lhWnd As Long)

m_lhWnd = FindWindowEx(lhWnd, 0, "Shell Embedding", vbNullString)
If (IsWindow(m_lhWnd) = 0) Or (IsWindow(lhWnd) = 0) Then Exit Sub
lpfnPreviousWindowProcedure = SetWindowLong(m_lhWnd, GWL_WNDPROC, _
AddressOf WindowProcedure)

End Sub

Public Sub Unhook()

Call SetWindowLong(m_lhWnd, GWL_WNDPROC, _
lpfnPreviousWindowProcedure)
m_lhWnd = 0

End Sub


'Form Code:

Private Sub Form_Load()
Call Hook(hWnd)
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call Unhook
End Sub

sunithi
Aug 6th, 2001, 08:43 PM
Thanx a lot. it worked !

Sunithi