Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / March 2005

Tip: Looking for answers? Try searching our database.

AxWebBrowser right click

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mystique - 03 Mar 2005 16:13 GMT
hi.
how can i disable the right mouse click on the AxWebBrowser in my
application?

thx in advance
Mystique
prakash.guru@gmail.com - 29 Mar 2005 13:28 GMT
Hi mystique
Try this...
U must implement the IDocHostUIHandler on your form.

Declare the following Interfaces And structurs.
-------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;

// IDocHostUIHandler interface

public enum DOCHOSTUIFLAG
{
    DOCHOSTUIFLAG_DIALOG = 0x1,
    DOCHOSTUIFLAG_DISABLE_HELP_MENU = 0x2,
    DOCHOSTUIFLAG_NO3DBORDER = 0x4,
    DOCHOSTUIFLAG_SCROLL_NO = 0x8,
    DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = 0x10,
    DOCHOSTUIFLAG_OPENNEWWIN = 0x20,
    DOCHOSTUIFLAG_DISABLE_OFFSCREEN = 0x40,
    DOCHOSTUIFLAG_FLAT_SCROLLBAR = 0x80,
    DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = 0x100,
    DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = 0x200,
    DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY = 0x400,
    DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = 0x800,
    DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = 0x1000,
    DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = 0x2000,
    DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = 0x4000,
    DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION = 0x10000,
    DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION = 0x20000,
    DOCHOSTUIFLAG_THEME = 0x40000,
    DOCHOSTUIFLAG_NOTHEME = 0x80000,
    DOCHOSTUIFLAG_NOPICS = 0x100000,
    DOCHOSTUIFLAG_NO3DOUTERBORDER = 0x200000
}

public enum DOCHOSTUIDBLCLK
{
    DOCHOSTUIDBLCLK_DEFAULT = 0,
    DOCHOSTUIDBLCLK_SHOWPROPERTIES = 1,
    DOCHOSTUIDBLCLK_SHOWCODE = 2
}

// MSG structure
[StructLayout(LayoutKind.Sequential)]public struct MSG
{
    public IntPtr hwnd;
    public int message;
    public int wParam;
    public int lParam;
    public int time;
    public tagPOINT pt;
}
[StructLayout(LayoutKind.Sequential, Pack=4)]
public struct tagRECT
{
    public int left;
    public int top;
    public int right;
    public int bottom;
}

[StructLayout(LayoutKind.Sequential, Pack=4)]
public struct tagPOINT
{
    public int x;
    public int y;
}

// DOCHOSTUIINFO structure
[StructLayout(LayoutKind.Sequential)]public struct DOCHOSTUIINFO
{
    public int cbSize;
    public DOCHOSTUIFLAG dwFlags;
    public DOCHOSTUIDBLCLK dwDoubleClick;
    public string pchHostCss;
    public string pchHostNS;
}

// OLEMENUGROUPWIDTHS structure
[StructLayout(LayoutKind.Sequential)]public struct OLEMENUGROUPWIDTHS
{
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=6)]public int[] width;
}

[StructLayout(LayoutKind.Sequential)]public struct OLECMDTEXT
{
    public UInt32 cmdtextf;
    public UInt32 cwActual;
    public UInt32 cwBuf;
    public char rgwz;
}

[StructLayout(LayoutKind.Sequential)]public struct OLECMD
{
    public long cmdID;
    public UInt64 cmdf;
}

// Interop definition for IOleCommandTarget.
[ComImport(), Guid("b722bccb-4e68-101b-a2bc-00aa00404770"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]public interface
IOleCommandTarget
{
    void QueryStatus (ref Guid pguidCmdGroup, UInt32 cCmds, [
MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1) ]OLECMD prgCmds,
ref OLECMDTEXT pCmdText);

    void Exec (ref Guid pguidCmdGroup, long nCmdId, long nCmdExecOpt, ref
object pvaIn, ref object pvaOut);
}

// ICustomDoc interface
[ComVisible(true), ComImport(),
Guid("3050f3f0-98b5-11cf-bb82-00aa00bdce0b"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]public
interface ICustomDoc
{
    void SetUIHandler (IDocHostUIHandler pUIHandler);
}

// IOleWindow interface
[ComVisible(true), ComImport(),
Guid("00000114-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]public
interface IOleWindow
{
    void GetWindow (IntPtr phwnd);
    void ContextSensitiveHelp (bool fEnterMode);
}

// IOleInPlaceActiveObject interface
[ComVisible(true), ComImport(),
Guid("00000117-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]public
interface IOleInPlaceActiveObject : IOleWindow
{

    // IOleWindow interface
    new  void GetWindow (IntPtr phwnd);
    new  void ContextSensitiveHelp (bool fEnterMode);
    void TranslateAccelerator (ref MSG lpmsg);
    void OnFrameWindowActivate (bool fActivate);
    void OnDocWindowActivate (bool fActivate);
    void ResizeBorder (ref tagRECT prcBorder, IOleInPlaceUIWindow
pUIWindow, bool fFrameWindow);
    void EnableModeless (bool fEnable);
}

// IOleInPlaceUIWindow interface
[ComVisible(true), ComImport(),
Guid("00000115-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]public
interface IOleInPlaceUIWindow : IOleWindow
{

    // IOleWindow interface
    new  void GetWindow (IntPtr phwnd);
    new  void ContextSensitiveHelp (bool fEnterMode);
    void GetBorder (ref tagRECT lprectBorder);
    void RequestBorderSpace (ref tagRECT pborderwidths);
    void SetBorderSpace (ref tagRECT pborderwidths);
    void SetActiveObject (IOleInPlaceActiveObject pActiveObject, string
pszObjName);
}

// IDropTarget interface
[ComVisible(true), ComImport(),
Guid("00000122-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]public
interface IDropTarget
{
    void DragEnter (IDataObject pDataObj, int grfKeyState, tagPOINT pt,
ref int pdwEffect);
    void DragOver (int grfKeyState, tagPOINT pt, ref int pdwEffect);
    void DragLeave ();
    void Drop (IDataObject pDataObj, int grfKeyState, tagPOINT pt, ref int
pdwEffect);
}

// IOleInPlaceFrame interface
[ComVisible(true), ComImport(),
Guid("00000116-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]public
interface IOleInPlaceFrame : IOleInPlaceUIWindow
{

    // IOleWindow interface
    new  void GetWindow (IntPtr phwnd);
    new  void ContextSensitiveHelp (bool fEnterMode);

    // IOleInPlaceUIWindow interface
    new void GetBorder (ref tagRECT lprectBorder);
    new void RequestBorderSpace (ref tagRECT pborderwidths);
    new void SetBorderSpace (ref tagRECT pborderwidths);
    new  void SetActiveObject (IOleInPlaceActiveObject pActiveObject,
string pszObjName);

    // TODO: hmenuShared should be a reference to a remotable handle
    void InsertMenus (IntPtr hmenuShared, ref OLEMENUGROUPWIDTHS
lpMenuWidths);
    void SetMenu (IntPtr hmenuShared, IntPtr holemenu, IntPtr
hwndActiveObject);
    void RemoveMenus (IntPtr hmenuShared);
    void SetStatusText (string pszStatusText);
    void EnableModeless (bool fEnable);
    void TranslateAccelerator (ref MSG lpmsg, UInt16 wID);
}

// IDocHostUIHandler interface
[ComVisible(true), ComImport(),
Guid("bd3f23c0-d43e-11cf-893b-00aa00bdce1a"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]public
interface IDocHostUIHandler
{

    [PreserveSig()] int ShowContextMenu(int dwID, ref tagPOINT ppt, [
MarshalAs(UnmanagedType.IUnknown) ]object pcmdtReserved, [
MarshalAs(UnmanagedType.IDispatch) ]object pdispReserved);

    void GetHostInfo (ref DOCHOSTUIINFO pInfo);

    [PreserveSig()] int ShowUI(int dwID, IOleInPlaceActiveObject
pActiveObject, IOleCommandTarget pCommandTarget, IOleInPlaceFrame
pFrame, IOleInPlaceUIWindow pDoc);

    void HideUI ();
    void UpdateUI ();
    void EnableModeless (bool fEnable);
    void OnDocWindowActivate (bool fActivate);
    void OnFrameWindowActivate (bool fActivate);

    void ResizeBorder (ref tagRECT prcBorder, IOleInPlaceUIWindow
pUIWindow, bool fFrameWindow);

    [PreserveSig()] int TranslateAccelerator(ref MSG lpMsg, ref Guid
pguidCmdGroup, int nCmdID);

    void GetOptionKeyPath (ref string pchKey, int dw);

    void GetDropTarget (IDropTarget pDropTarget, ref IDropTarget
ppDropTarget);

    void GetExternal ([ MarshalAs(UnmanagedType.IDispatch) ]ref object
ppDispatch);

    [PreserveSig()] int TranslateUrl(int dwTranslate, ref UInt16 pchURLIn,
IntPtr ppchURLOut);

    [PreserveSig()] int FilterDataObject(IDataObject pDO, ref IDataObject
ppDORet);
}

-----------------------------------------------------------------------------

On the form (which having the webbrowser control)
make it implement from IDocHostUIHandler

And Implement the following Methods.
-----------------------------------------------------------------------------
public void EnableModeless (bool fEnable)
        {
            //Do nothing
        }
        public int FilterDataObject(System.Windows.Forms.IDataObject pDO, ref
System.Windows.Forms.IDataObject ppDORet)
        {
            //Do nothing
            return S_FALSE;
        }
        public void GetDropTarget (IDropTarget pDropTarget, ref IDropTarget
ppDropTarget)
        {
            //Do nothing
        }

        public void GetExternal (ref object ppDispatch)
        {
            //Do nothing
        }

        public void GetHostInfo (ref DOCHOSTUIINFO pInfo)
        {
            pInfo.cbSize = pInfo.ToString().Length;
            pInfo.dwFlags = DOCHOSTUIFLAG.DOCHOSTUIFLAG_NO3DOUTERBORDER |
DOCHOSTUIFLAG.DOCHOSTUIFLAG_NO3DBORDER |
DOCHOSTUIFLAG.DOCHOSTUIFLAG_FLAT_SCROLLBAR;
            pInfo.dwDoubleClick = DOCHOSTUIDBLCLK.DOCHOSTUIDBLCLK_DEFAULT;
        }
        public void GetOptionKeyPath (ref string pchKey, int dw)
        {
            //Do nothing
        }

        public void HideUI ()
        {
            //Do nothing
        }

        public void OnDocWindowActivate (bool fActivate)
        {
            //Do nothing
        }
        public void OnFrameWindowActivate (bool fActivate)
        {
            //Do nothing
        }

        public void ResizeBorder (ref tagRECT prcBorder, IOleInPlaceUIWindow
pUIWindow, bool fFrameWindow)
        {

        }
        public int ShowUI(int dwID, IOleInPlaceActiveObject pActiveObject,
IOleCommandTarget pCommandTarget, IOleInPlaceFrame pFrame,
IOleInPlaceUIWindow pDoc)
        {
            //Do nothing
            return S_FALSE;
        }

        public int ShowContextMenu(int dwID, ref tagPOINT ppt, object
pcmdtReserved, object pdispReserved)
        {
            //Do nothing
            return S_OK;
        }
        public int TranslateAccelerator(ref MSG lpMsg, ref System.Guid
pguidCmdGroup, int nCmdID)
        {
            return S_OK;
        }
        public int TranslateUrl(int dwTranslate, ref System.UInt16 pchURLIn,
System.IntPtr ppchURLOut)
        {
            //Do nothing
            return S_FALSE;
        }
        public void UpdateUI ()
        {
            //Do nothing
        }
------------------------------------------------------------------------------
private void SetUIHandler()
{
    //                            browser control Name
       ICustomDoc icd = (ICustomDoc) WebBrowser.Document;
    icd.SetUIHandler(this);
}

call SetUIHandler function in Form's Load Event
------------------------------------------------------------------------------

The Key behind this is overriding the ShowContextMenu function and
return S_OK.
S_OK means the user display his own menu.
http://msdn.microsoft.com/workshop/browser/hosting/reference/ifaces/idochostuiha
ndler/showcontextmenu.asp


Regards
Prakash

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.