Override WebBrowser Control right click

How do you override the WebBrowser controls default right click menu and use one of your own, I know how to create right click menus and how to override menu's for other controls but do not know how to for a control like WEbBrowser which has no mouse events (except drag and drop)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You must subclass windows to intercept the mouse click.  Use the following code:

'Insert this into the form that contains your webbrowser:

Private Sub Form_Load()
    'Start Trapping Right-Mouse clicks in WebBrowser Control:
    gLngMouseHook = SetWindowsHookEx(WH_MOUSE, AddressOf MouseHookProc, App.hInstance, GetCurrentThreadId)

End Sub

Private Sub Form_Unload(Cancel As Integer)
'Cancel the trapping of the code
UnhookWindowsHookEx gLngMouseHook

End Sub

'Add this to a BAS module:

Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lparam As Any) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Const WM_RBUTTONUP = &H205
Public Const WH_MOUSE = 7

Public Type POINTAPI
    x As Long
    y As Long
End Type

    pt As POINTAPI
    hwnd As Long
    wHitTestCode As Long
    dwExtraInfo As Long
End Type
Public gLngMouseHook As Long
Public Function MouseHookProc(ByVal nCode As Long, ByVal wParam As Long, mhs As MOUSEHOOKSTRUCT) As Long
Dim strBuffer As String
Dim lngBufferLen As Long
Dim strClassName As String
Dim lngResult As Long

If (nCode >= 0 And wParam = WM_RBUTTONUP) Then

        'Preinitialize string
        strBuffer = Space(255)
       ' lngBufferLen = Len(strBuffer)
        'This is the string that holds the class name that we are looking for
        strClassName = "Internet Explorer_Server"
        Debug.Print strClassName
        'Get the classname for the Window that has been clicked, making sure something is returned
        'If the function returns 0, it has failed
        lngResult = GetClassName(mhs.hwnd, strBuffer, Len(strBuffer))
        Debug.Print Left$(strBuffer, lngResult)
        If lngResult > 0 Then

            'Check to see if the class of the window we clicked on is the same as above
            If Left$(strBuffer, lngResult) = strClassName Then
                'Value is the same. Squash the command
                MouseHookProc = 1
                Exit Function
            End If
        End If

    End If

MouseHookProc = CallNextHookEx(gLngMouseHook, nCode, wParam, mhs)
End Function


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Have been searching for a similar answer for a while now. Please look at Q.10231342 and add your $.02...

2GreyAuthor Commented:
Sorry for the long time in responding, have been away on vacation, It worked well for brining up my own menu. I was wondering if you or anyone else could tell me how to view Q.10231342, I am new to this forum and am not fully aware on how to use it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.