Web Browser control - any way to disable sub-menu

Posted on 1998-07-16
Last Modified: 2010-05-03
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.
Question by:dgb001
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1465960
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.

Author Comment

ID: 1465961
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.

Expert Comment

ID: 1465962
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.
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.


Author Comment

ID: 1465963
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.


Expert Comment

ID: 1465964
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.

Expert Comment

ID: 1465965

Expert Comment

ID: 1465966

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.

Author Comment

ID: 1465967
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.


Accepted Solution

madumas earned 20 total points
ID: 1465968

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:

Author Comment

ID: 1465969
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.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How does CurrentUser work? 10 43
Protecting vb6 & .Net code Obfuscation 18 213
Export Data to Different .csv Files 27 131
Get the Y value of a line at X in a chart in VBA 28 73
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question