Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Web Browser control - any way to disable sub-menu

Posted on 1998-07-16
Medium Priority
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.
Technology Partners: 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!


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 60 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

688 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