Results 1 to 3 of 3

Thread: Disabling Mouse button

  1. #1

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    India
    Posts
    35

    Cool Disabling Mouse button

    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
    I believe... in myself

  2. #2
    Matthew Gates
    Guest
    Try this:


    VB Code:
    1. 'Author: Yonatan
    2. 'Origin: [url]http://www.vbforums.com[/url]
    3. 'Purpose: Disable Right Click in Webbrowser
    4. 'Version: VB5+
    5.  
    6.  
    7. 'Module Code:
    8.  
    9. Option Explicit
    10.  
    11. Private Declare Function CallWindowProc Lib "user32" _
    12. Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As _
    13. Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) _
    14. As Long
    15.  
    16. Private Declare Function SetWindowLong Lib "user32" _
    17. Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, _
    18. ByVal dwNewLong As Long) As Long
    19.  
    20. Private Declare Function IsWindow Lib "user32" (ByVal hWnd As Long) _
    21. As Long
    22.  
    23. Private Declare Function FindWindowEx Lib "user32" _
    24. Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
    25. ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    26.  
    27. Private Const GWL_WNDPROC = (-4)
    28. Public Const WM_MOUSEACTIVATE = &H21
    29. Public Const MA_ACTIVATEANDEAT = 2
    30. Private lpfnPreviousWindowProcedure As Long
    31. Private m_lhWnd As Long
    32.  
    33. Private Function WindowProcedure(ByVal hWnd As Long, ByVal uMsg As _
    34. Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    35.  
    36.     If (uMsg = WM_MOUSEACTIVATE) And (lParam = &H2040001) Then ' Don't ask about the lParam...
    37.         WindowProcedure = MA_ACTIVATEANDEAT
    38.         Exit Function
    39.     End If
    40.     WindowProcedure = CallWindowProc(lpfnPreviousWindowProcedure, _
    41.     hWnd, uMsg, wParam, lParam)
    42.  
    43. End Function
    44.  
    45. Public Sub Hook(ByVal lhWnd As Long)
    46.  
    47.     m_lhWnd = FindWindowEx(lhWnd, 0, "Shell Embedding", vbNullString)
    48.     If (IsWindow(m_lhWnd) = 0) Or (IsWindow(lhWnd) = 0) Then Exit Sub
    49.     lpfnPreviousWindowProcedure = SetWindowLong(m_lhWnd, GWL_WNDPROC, _
    50.     AddressOf WindowProcedure)
    51.  
    52. End Sub
    53.  
    54. Public Sub Unhook()
    55.  
    56.     Call SetWindowLong(m_lhWnd, GWL_WNDPROC, _
    57.     lpfnPreviousWindowProcedure)
    58.     m_lhWnd = 0
    59.  
    60. End Sub
    61.  
    62.  
    63. 'Form Code:
    64.  
    65. Private Sub Form_Load()
    66.     Call Hook(hWnd)
    67. End Sub
    68.  
    69. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    70.     Call Unhook
    71. End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    India
    Posts
    35

    Disabling Mouse Button

    Thanx a lot. it worked !

    Sunithi
    I believe... in myself

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width