Web Browser control - any way to disable sub-menu

I'm using a couple of web browser controls to create a help system, by using HTML. Only thing is that the user could view the HTML source by right-clicking on the web control, which I don't really want to happen. I know there is such a thing as compiled HTML, but don't really know anything about this or if it would be a solution. Really I just want to be able to disable the sub-menu. Thanks in advance.
Who is Participating?

I found that... I haven't tryed it, but it should work....

In your module.bas file you *need* to add this code:

'Declarations for Preventing Right-Click in WebBrowser Control:
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
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long)
As Long
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal
nCode As Long, ByVal wParam As Long, lparam As Any) As Long
Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal
hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As

Public Const WM_RBUTTONUP = &H205
Public Const WH_MOUSE = 7

    x As Long
    y As Long
End Type

    pt As POINTAPI
    hwnd As Long
    wHitTestCode As Long
    dwExtraInfo As Long
End Type

Public l_hMouseHook As Long

Then you need to add this in your program:

Private Function MouseHookProc(ByVal nCode As Long, ByVal wParam As
'Prevent Right-Click in WebBrowser Control:
    If (nCode >= 0 And wParam = WM_RBUTTONUP) Then
        Dim sClassName As String
        Dim sTestClass As String
        sTestClass = "HTML_Internet Explorer"
        sClassName = String$(256, 0)
        If GetClassName(mhs.hwnd, sClassName, Len(sClassName)) > 0 Then
            If Left$(sClassName, Len(sTestClass)) = sTestClass Then
                MouseHookProc = 1
                Exit Function
            End If
        End If
    End If
        MouseHookProc = CallNextHookEx(l_hMouseHook, nCode, wParam, mhs)
End Function

I took this at:
1) The web browser control may have a method which allows you to add/remove options from the context sensitive (right-click) menu. If so, then try using it to remove the option allowing source viewing - query the control's vendor re this option

2) intercept the right click when it is over the control & generate your own context sensitive (right-click) menu. If you find this difficult with a third party control then lay a frame or some form of transparent window over the co-ords of the control & it should be able to intercept the mouse. Pass through all events except the right-mouse.
dgb001Author Commented:
Thanks for the input Immanuel, but there is no option as you suggested where you can remove/add items to the sub-menu - also, this is not a third party control, it's Microsoft's own ActiveX browser control which ships with VB5.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

If you were to setup a handler which watched all the windows messages and cancelled a right-mouse click to the handle of the WebBrowser component you should be able to disable the menu completely.
dgb001Author Commented:
I'm sure you may well be right, but I was really hoping for something a little more simple. However, given that I haven't any alternatives yet then I'd be interested to know exactly how I would go about doing this, not having played with window handles etc. But I appreciate your response, thankyou.

There may be an easier answer, but I think you would have to use something like SetWindowsHook with the WH_GETMESSAGE parameter and point it to your message filter.  You would then use something like PeekMessage in that filter procedure and remove any WM_RBUTTONDOWN messages going to the handle of the WebBrowser control.

Here's another solution. Try using the MS HTML Help program. It might do what you want your program to do. You can find more info at the following URL.

dgb001Author Commented:
Thanks Jason, I'm not rejecting it (well only temporarily) - I'll have a look to see what the MS stuff is like - if I find it does what I want then we'll work a way to give you the points. The only reason I'm doing this is just so other people can have an opportunity to answer as well. Thanks again.

dgb001Author Commented:
Yes, that looks good, so the points are yours - though I'm presently unable to actually understand all of it. If you know how to actually get it to work then I'd be glad to know more. (ie. I assume that the function gets called from somewhere and that MOUSEHOOKINSTRUCT needs setting up before you do this, or maybe I'm missing the point somewhere along the line) - many thanks anyway.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.