Hi Charles,
Can I assume all the HRESULT function returns should be replaced with an
Integer return?
eg <PreserveSig()> Function GetHostInfo(ByRef pInfo As DOCHOSTUIINFO) As
HRESULT
.... should be As Integer?
Also, there are many references to tagPOINT and tagRECT in the code, can I
safely assume these are identical to the POINT and RECT types declared in
the Win32 API, or is there something special about their layout?
Many thanks,
Alex Clark
"Charles Law" <blank@nowhere.com> wrote in message
news:OPTGmSyyEHA.1392@TK2MSFTNGP14.phx.gbl...[color=blue]
> Hi Alex
>
> Here are my implementations. ShowContextMenu is the first method in
> IDocHostUIHandler.
>
> <code>
> ' IDocHostUIHandler interface
> <ComVisible(True), ComImport(),
> Guid("bd3f23c0-d43e-11cf-893b-00aa00bdce1a"), _
> InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIUnknown)> _
> Public Interface IDocHostUIHandler
>
> <PreserveSig()> Function ShowContextMenu(ByVal dwID As Integer, ByRef
> ppt As tagPOINT, _
> <MarshalAs(UnmanagedType.IUnknown)> ByVal pcmdtReserved As Object, _
> <MarshalAs(UnmanagedType.IDispatch)> ByVal pdispReserved As Object) As
> HRESULT
>
> <PreserveSig()> Function GetHostInfo(ByRef pInfo As DOCHOSTUIINFO) As
> HRESULT
>
> <PreserveSig()> Function ShowUI(ByVal dwID As Integer, ByVal
> pActiveObject As IOleInPlaceActiveObject, _
> ByVal pCommandTarget As IOleCommandTarget, ByVal pFrame As
> IOleInPlaceFrame, ByVal pDoc As IOleInPlaceUIWindow) As HRESULT
>
> <PreserveSig()> Function HideUI() As HRESULT
> <PreserveSig()> Function UpdateUI() As HRESULT
> <PreserveSig()> Function EnableModeless(ByVal fEnable As Boolean) As
> HRESULT
> <PreserveSig()> Function OnDocWindowActivate(ByVal fActivate As
> Boolean) As HRESULT
> <PreserveSig()> Function OnFrameWindowActivate(ByVal fActivate As
> Boolean) As HRESULT
> <PreserveSig()> Function ResizeBorder(ByRef prcBorder As tagRECT, ByVal
> pUIWindow As IOleInPlaceUIWindow, ByVal fFrameWindow As Boolean) As
> HRESULT
> <PreserveSig()> Function TranslateAccelerator(ByRef lpMsg As MSG, ByRef
> pguidCmdGroup As Guid, ByVal nCmdID As Integer) As HRESULT
> <PreserveSig()> Function GetOptionKeyPath(ByRef pbstrKey As IntPtr,
> ByVal dw As Integer) As HRESULT
> <PreserveSig()> Function GetDropTarget(ByVal pDropTarget As
> IDropTarget, ByRef ppDropTarget As IDropTarget) As HRESULT
> <PreserveSig()> Function
> GetExternal(<MarshalAs(UnmanagedType.IDispatch)> ByRef ppDispatch As
> Object) As HRESULT
> <PreserveSig()> Function TranslateUrl(ByVal dwTranslate As Integer,
> ByVal strURLIn As String, ByRef pstrURLOut As String) As HRESULT
> <PreserveSig()> Function FilterDataObject(ByVal pDO As IDataObject,
> ByRef ppDORet As IDataObject) As HRESULT
>
> End Interface
>
> Public Enum OLECMDTEXTF
> OLECMDTEXTF_NONE = 0
> OLECMDTEXTF_NAME = 1
> OLECMDTEXTF_STATUS = 2
> End Enum
>
> ' OLECMD
> <StructLayout(LayoutKind.Sequential)> _
> Public Structure OLECMD
> Public cmdID As Int32
> Public cmdf As Int32
> End Structure
>
> ' OLECMDTEXT
> <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.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(UnmanagedType.ByValTStr, SizeConst:=256)> _
> Public text As String
> End Class
>
> <StructLayout(LayoutKind.Explicit)> _
> 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(ByVal Value As String)
>
> ' Identify this as a BSTR
> vt = CType(vt Or VarEnum.VT_BSTR, Short)
>
> bstrVal = Marshal.StringToBSTR(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.AllocCoTaskMem(Marshal.SizeOf(Me.GetType() ))
> Marshal.StructureToPtr(Me, p, False)
> Return Marshal.GetObjectForNativeVariant(p)
> Finally
> 'Called no matter what
> Marshal.FreeCoTaskMem(p)
> End Try
> End Function
>
> <DllImport("Oleaut32.dll", PreserveSig:=False)> _
> Private Shared Sub VariantClear(ByVal var As OLEVARIANT)
> End Sub
>
> End Class 'OLEVARIANT
>
> ' IOleCommandTarget interface
> <ComVisible(True), ComImport(),
> Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), _
> InterfaceType(ComInterfaceType.InterfaceIsIUnknown )> _
> Public Interface IOleCommandTarget
>
> Sub QueryStatus(ByRef pguidCmdGroup As Guid, ByVal cCmds As Int32, _
> <InAttribute(), Out(), MarshalAs(UnmanagedType.LPArray,
> 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" <alex@theclarkhome.SPAMTIN.net> wrote in message
> news:eiOSThxyEHA.4028@TK2MSFTNGP15.phx.gbl...[color=green]
>> Hi Charles,
>>
>> The code seems to be missing a few bits and bobs, namely the
>> implementation of the IOleCommandTarget interface which is required for
>> one of the methods in the IDocHostUIHandler. Also, ShowContextMenu does
>> not appear to be a method within IDocHostUIHandler anywhere?
>>
>> Thanks,
>> Alex Clark
>>
>>
>>
>> "Charles Law" <blank@nowhere.com> wrote in message
>> news:%23ziRGKXyEHA.4028@TK2MSFTNGP09.phx.gbl...[color=darkred]
>>> Hi Alex
>>>
>>> The interface you need to implement is IDocHostUIHandler. 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
>>> IDocHostUIHandler. Then, in the DocumentComplete 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" <alex@theclarkhome.SPAMTIN.net> wrote in message
>>> news:%23A7Q01NyEHA.2200@TK2MSFTNGP09.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
>>>>
>>>>
>>>
>>>[/color]
>>
>>[/color]
>
>[/color]