Solved

Web Browser control - any way to disable sub-menu

Posted on 1998-07-16
10
192 Views
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.
0
Comment
Question by:dgb001
10 Comments
 

Expert Comment

by:ImmanuelOnse
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.
0
 
LVL 1

Author Comment

by:dgb001
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.
 
0
 
LVL 1

Expert Comment

by:rocca
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.
0
 
LVL 1

Author Comment

by:dgb001
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.

0
 
LVL 1

Expert Comment

by:rocca
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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Expert Comment

by:rocca
ID: 1465965
0
 
LVL 1

Expert Comment

by:Jason_Row
ID: 1465966
dgb001,

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.

http://www.microsoft.com/workshop/c-frame.htm#/workshop/author/htmlhelp/default.asp
0
 
LVL 1

Author Comment

by:dgb001
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.

0
 

Accepted Solution

by:
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
Long

Public Const WM_RBUTTONUP = &H205
Public Const WH_MOUSE = 7

Type POINTAPI
    x As Long
    y As Long
End Type

Type MOUSEHOOKSTRUCT
    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
Long, mhs As MOUSEHOOKSTRUCT) As Long
'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:
http://www.geocities.com/CapeCanaveral/Lab/1961/dismouse.txt
0
 
LVL 1

Author Comment

by:dgb001
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.
                 davidbird@softhome.net

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now