Hi Alex
Here are my implementations . ShowContextMenu is the first method in
IDocHostUIHandl er.
<code>
' IDocHostUIHandl er interface
<ComVisible(Tru e), ComImport(),
Guid("bd3f23c0-d43e-11cf-893b-00aa00bdce1a"), _
InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
Public Interface IDocHostUIHandl er
<PreserveSig( )> Function ShowContextMenu (ByVal dwID As Integer, ByRef
ppt As tagPOINT, _
<MarshalAs(Unma nagedType.IUnkn own)> ByVal pcmdtReserved As Object, _
<MarshalAs(Unma nagedType.IDisp atch)> ByVal pdispReserved As Object) As
HRESULT
<PreserveSig( )> Function GetHostInfo(ByR ef pInfo As DOCHOSTUIINFO) As
HRESULT
<PreserveSig( )> Function ShowUI(ByVal dwID As Integer, ByVal
pActiveObject As IOleInPlaceActi veObject, _
ByVal pCommandTarget As IOleCommandTarg et, ByVal pFrame As
IOleInPlaceFram e, ByVal pDoc As IOleInPlaceUIWi ndow) As HRESULT
<PreserveSig( )> Function HideUI() As HRESULT
<PreserveSig( )> Function UpdateUI() As HRESULT
<PreserveSig( )> Function EnableModeless( ByVal fEnable As Boolean) As
HRESULT
<PreserveSig( )> Function OnDocWindowActi vate(ByVal fActivate As Boolean)
As HRESULT
<PreserveSig( )> Function OnFrameWindowAc tivate(ByVal fActivate As
Boolean) As HRESULT
<PreserveSig( )> Function ResizeBorder(By Ref prcBorder As tagRECT, ByVal
pUIWindow As IOleInPlaceUIWi ndow, ByVal fFrameWindow As Boolean) As HRESULT
<PreserveSig( )> Function TranslateAccele rator(ByRef lpMsg As MSG, ByRef
pguidCmdGroup As Guid, ByVal nCmdID As Integer) As HRESULT
<PreserveSig( )> Function GetOptionKeyPat h(ByRef pbstrKey As IntPtr,
ByVal dw As Integer) As HRESULT
<PreserveSig( )> Function GetDropTarget(B yVal pDropTarget As IDropTarget,
ByRef ppDropTarget As IDropTarget) As HRESULT
<PreserveSig( )> Function
GetExternal(<Ma rshalAs(Unmanag edType.IDispatc h)> ByRef ppDispatch As Object)
As HRESULT
<PreserveSig( )> Function TranslateUrl(By Val dwTranslate As Integer,
ByVal strURLIn As String, ByRef pstrURLOut As String) As HRESULT
<PreserveSig( )> Function FilterDataObjec t(ByVal pDO As IDataObject,
ByRef ppDORet As IDataObject) As HRESULT
End Interface
Public Enum OLECMDTEXTF
OLECMDTEXTF_NON E = 0
OLECMDTEXTF_NAM E = 1
OLECMDTEXTF_STA TUS = 2
End Enum
' OLECMD
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure OLECMD
Public cmdID As Int32
Public cmdf As Int32
End Structure
' OLECMDTEXT
<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Unicode)> _
Public Class OLECMDTEXT
Public cmdtextf As OLECMDTEXTF
Public cwActual As Int32
Private cwBuf As Int32 = 256 'Make sure this is the same as SizeConst
below
<MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=256) > _
Public text As String
End Class
<StructLayout(L ayoutKind.Expli cit)> _
Public Class OLEVARIANT
<FieldOffset(0) > Public vt As System.Int16
<FieldOffset(2) > Public wReserved1 As System.Int16
<FieldOffset(4) > Public wReserved2 As System.Int16
<FieldOffset(6) > Public wReserved3 As System.Int16
<FieldOffset(8) > Public lVal As Integer
<FieldOffset(8) > Public iVal As Short
<FieldOffset(8) > Public bstrVal As IntPtr
<FieldOffset(8) > Public pUnkVal As IntPtr
<FieldOffset(8) > Public pArray As IntPtr
<FieldOffset(8) > Public pvRecord As IntPtr
<FieldOffset(12 )> Public pRecInfo As IntPtr
Public Sub Clear()
VariantClear(Me )
End Sub 'Clear
Public Sub LoadString(ByVa l Value As String)
' Identify this as a BSTR
vt = CType(vt Or VarEnum.VT_BSTR , Short)
bstrVal = Marshal.StringT oBSTR(Value)
End Sub
Public Function ToNativeObject( ) As Object
Dim p As IntPtr
Try
'Allocate a buffer to hold the data in this OLEVARIANT
p = Marshal.AllocCo TaskMem(Marshal .SizeOf(Me.GetT ype()))
Marshal.Structu reToPtr(Me, p, False)
Return Marshal.GetObje ctForNativeVari ant(p)
Finally
'Called no matter what
Marshal.FreeCoT askMem(p)
End Try
End Function
<DllImport("Ole aut32.dll", PreserveSig:=Fa lse)> _
Private Shared Sub VariantClear(By Val var As OLEVARIANT)
End Sub
End Class 'OLEVARIANT
' IOleCommandTarg et interface
<ComVisible(Tru e), ComImport(),
Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), _
InterfaceType(C omInterfaceType .InterfaceIsIUn known)> _
Public Interface IOleCommandTarg et
Sub QueryStatus(ByR ef pguidCmdGroup As Guid, ByVal cCmds As Int32, _
<InAttribute( ), Out(), MarshalAs(Unman agedType.LPArra y,
SizeParamIndex: =1)> ByVal prgCmds() As OLECMD, <InAttribute( ), Out()> ByVal
pCmdText As OLECMDTEXT)
Sub Exec(ByRef pguidCmdGroup As Guid, ByVal nCmdId As Int32, _
ByVal nCmdExecOpt As Int32, ByVal pvaIn As OLEVARIANT, ByVal pvaOut
As OLEVARIANT)
End Interface
</code>
Let me know if I have missed anything else.
HTH
Charles
"Alex Clark" <al**@theclarkh ome.SPAMTIN.net > wrote in message
news:ei******** ******@TK2MSFTN GP15.phx.gbl...
Hi Charles,
The code seems to be missing a few bits and bobs, namely the
implementation of the IOleCommandTarg et interface which is required for
one of the methods in the IDocHostUIHandl er. Also, ShowContextMenu does
not appear to be a method within IDocHostUIHandl er anywhere?
Thanks,
Alex Clark
"Charles Law" <bl***@nowhere. com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Hi Alex
The interface you need to implement is IDocHostUIHandl er. It has a method
ShowContextMenu . If you return an HRESULT of S_OK in your implementation
of this method this will cancel the context menu on right-click. It also
allows you to implement your own context menu.
In your form that host the WebBrowser control, implement
IDocHostUIHandl er. Then, in the DocumentComplet e event, get the
ICustomDoc interface from the document object, and call SetUIHandler(Me ).
Finally, wait for the readystate to go to complete.
You could have a look at this complete thread:
http://groups.google.com/groups?q=id...phx.gbl&rnum=7
HTH
Charles
"Alex Clark" <al**@theclarkh ome.SPAMTIN.net > wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Hi All,
I'm sure this must have been asked a million times due to it's
usefulness, but are there any sensible solutions for disabling right
click (and other services such as Ctrl+P, Browser hotkeys etc) on a
Web-Browser control in VB.NET?
Despite Googling for ideas on and off for a week now, I only found one
solution and this was to implement IMessageFilter on the form and then
trap all the incoming messages. Unfortunately, this also prevents the
user from being able to move my application (something to do with
trapping right clicks), along with other useful things like being able
to use the backspace key!
Is there any other way of doing this? Or is there some way I can trap
messages that go into the Web-browser control BEFORE it processes them
and AFTER my Form has? Surely somebody must have come up with an
efficient way of hosting a customized browser in a .NET WinForm!
TIA
Alex Clark