Hi Gokul
Ok, here goes. It works something like this.
First, include the following interface definition stuff somewhere convenient
(I have a separate module with these kind of interfaces in):
<code>
Public Enum DOCHOSTUIFLAG
DOCHOSTUIFLAG_DIALOG = &H1
DOCHOSTUIFLAG_DISABLE_HELP_MENU = &H2
DOCHOSTUIFLAG_NO3DBORDER = &H4
DOCHOSTUIFLAG_SCROLL_NO = &H8
DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = &H10
DOCHOSTUIFLAG_OPENNEWWIN = &H20
DOCHOSTUIFLAG_DISABLE_OFFSCREEN = &H40
DOCHOSTUIFLAG_FLAT_SCROLLBAR = &H80
DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = &H100
DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = &H200
DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY = &H400
DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = &H800
DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = &H1000
DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = &H2000
DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = &H4000
DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION = &H10000
DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION = &H20000
DOCHOSTUIFLAG_THEME = &H40000
DOCHOSTUIFLAG_NOTHEME = &H80000
DOCHOSTUIFLAG_NOPICS = &H100000
DOCHOSTUIFLAG_NO3DOUTERBORDER = &H200000
End Enum
Public Enum DOCHOSTUIDBLCLK
DOCHOSTUIDBLCLK_DEFAULT = 0
DOCHOSTUIDBLCLK_SHOWPROPERTIES = 1
DOCHOSTUIDBLCLK_SHOWCODE = 2
End Enum
' MSG structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure MSG
Dim hwnd As IntPtr
Dim message As Integer
Dim wParam As Integer
Dim lParam As Integer
Dim time As Integer
Dim pt As tagPOINT
End Structure
' DOCHOSTUIINFO structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure DOCHOSTUIINFO
Dim cbSize As Integer
Dim dwFlags As DOCHOSTUIFLAG
Dim dwDoubleClick As DOCHOSTUIDBLCLK
Dim pchHostCss As String
Dim pchHostNS As String
End Structure
' OLEMENUGROUPWIDTHS structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure OLEMENUGROUPWIDTHS
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=6)> _
Dim width() As Integer
End Structure
' ICustomDoc interface
<ComVisible(True), ComImport(),
Guid("3050f3f0-98b5-11cf-bb82-00aa00bdce0b"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface ICustomDoc
Sub SetUIHandler(ByVal pUIHandler As IDocHostUIHandler)
End Interface
' IOleWindow interface
<ComVisible(True), ComImport(),
Guid("00000114-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleWindow
Sub GetWindow(ByVal phwnd As IntPtr)
Sub ContextSensitiveHelp(ByVal fEnterMode As Boolean)
End Interface
' IOleInPlaceActiveObject interface
<ComVisible(True), ComImport(),
Guid("00000117-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleInPlaceActiveObject : Inherits IOleWindow
' IOleWindow interface
Shadows Sub GetWindow(ByVal phwnd As IntPtr)
Shadows Sub ContextSensitiveHelp(ByVal fEnterMode As Boolean)
Sub TranslateAccelerator(ByRef lpmsg As MSG)
Sub OnFrameWindowActivate(ByVal fActivate As Boolean)
Sub OnDocWindowActivate(ByVal fActivate As Boolean)
Sub ResizeBorder(ByRef prcBorder As tagRECT, ByVal pUIWindow As
IOleInPlaceUIWindow, ByVal fFrameWindow As Boolean)
Sub EnableModeless(ByVal fEnable As Boolean)
End Interface
' IOleInPlaceUIWindow interface
<ComVisible(True), ComImport(),
Guid("00000115-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleInPlaceUIWindow : Inherits IOleWindow
' IOleWindow interface
Shadows Sub GetWindow(ByVal phwnd As IntPtr)
Shadows Sub ContextSensitiveHelp(ByVal fEnterMode As Boolean)
Sub GetBorder(ByRef lprectBorder As tagRECT)
Sub RequestBorderSpace(ByRef pborderwidths As tagRECT)
Sub SetBorderSpace(ByRef pborderwidths As tagRECT)
Sub SetActiveObject(ByVal pActiveObject As IOleInPlaceActiveObject,
ByVal pszObjName As String)
End Interface
' IDropTarget interface
<ComVisible(True), ComImport(),
Guid("00000122-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IDropTarget
Sub DragEnter(ByVal pDataObj As IDataObject, ByVal grfKeyState As
Integer, ByVal pt As tagPOINT, ByRef pdwEffect As Integer)
Sub DragOver(ByVal grfKeyState As Integer, ByVal pt As tagPOINT, ByRef
pdwEffect As Integer)
Sub DragLeave()
Sub Drop(ByVal pDataObj As IDataObject, ByVal grfKeyState As Integer,
ByVal pt As tagPOINT, ByRef pdwEffect As Integer)
End Interface
' IOleInPlaceFrame interface
<ComVisible(True), ComImport(),
Guid("00000116-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleInPlaceFrame : Inherits IOleInPlaceUIWindow
' IOleWindow interface
Shadows Sub GetWindow(ByVal phwnd As IntPtr)
Shadows Sub ContextSensitiveHelp(ByVal fEnterMode As Boolean)
' IOleInPlaceUIWindow interface
Shadows Sub GetBorder(ByRef lprectBorder As tagRECT)
Shadows Sub RequestBorderSpace(ByRef pborderwidths As tagRECT)
Shadows Sub SetBorderSpace(ByRef pborderwidths As tagRECT)
Shadows Sub SetActiveObject(ByVal pActiveObject As
IOleInPlaceActiveObject, ByVal pszObjName As String)
' TODO: hmenuShared should be a reference to a remotable handle
Sub InsertMenus(ByVal hmenuShared As IntPtr, ByRef lpMenuWidths As
OLEMENUGROUPWIDTHS)
Sub SetMenu(ByVal hmenuShared As IntPtr, ByVal holemenu As IntPtr, ByVal
hwndActiveObject As IntPtr)
Sub RemoveMenus(ByVal hmenuShared As IntPtr)
Sub SetStatusText(ByVal pszStatusText As String)
Sub EnableModeless(ByVal fEnable As Boolean)
Sub TranslateAccelerator(ByRef lpmsg As MSG, ByVal wID As UInt16)
End Interface
' IDocHostUIHandler interface
<ComVisible(True), ComImport(),
Guid("bd3f23c0-d43e-11cf-893b-00aa00bdce1a"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
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 Integer
Sub GetHostInfo(ByRef pInfo As DOCHOSTUIINFO)
<PreserveSig()> _
Function ShowUI( _
ByVal dwID As Integer, _
ByVal pActiveObject As IOleInPlaceActiveObject, _
ByVal pCommandTarget As IOleCommandTarget, _
ByVal pFrame As IOleInPlaceFrame, _
ByVal pDoc As IOleInPlaceUIWindow) As Integer
Sub HideUI()
Sub UpdateUI()
Sub EnableModeless(ByVal fEnable As Boolean)
Sub OnDocWindowActivate(ByVal fActivate As Boolean)
Sub OnFrameWindowActivate(ByVal fActivate As Boolean)
Sub ResizeBorder( _
ByRef prcBorder As tagRECT, _
ByVal pUIWindow As IOleInPlaceUIWindow, _
ByVal fFrameWindow As Boolean)
<PreserveSig()> _
Function TranslateAccelerator( _
ByRef lpMsg As MSG, _
ByRef pguidCmdGroup As Guid, _
ByVal nCmdID As Integer) As Integer
Sub GetOptionKeyPath( _
ByRef pchKey As String, _
ByVal dw As Integer)
Sub GetDropTarget( _
ByVal pDropTarget As IDropTarget, _
ByRef ppDropTarget As IDropTarget)
Sub GetExternal(<MarshalAs(UnmanagedType.IDispatch)> ByRef ppDispatch As
Object)
<PreserveSig()> _
Function TranslateUrl( _
ByVal dwTranslate As Integer, _
ByRef pchURLIn As UInt16, _
ByVal ppchURLOut As IntPtr) As Integer
<PreserveSig()> _
Function FilterDataObject( _
ByVal pDO As IDataObject, _
ByRef ppDORet As IDataObject) As Integer
End Interface
</code>
Next, create a class (I call mine DocHostUIHandler) and implement
IDocHostUIHandler. If you are using V2003 you will get all the subs and
functions filled in for you; wonderful.
For convenience, define the following at the top of the class.
<code>
Private Const S_OK As Integer = 0
Private Const S_FALSE As Integer = 1
</code>
For every function that you are not going to intercept, return S_FALSE. That
will signal that you have not provided your own implementation. If you want
to prevent something, like the context menu, you can return S_TRUE in
ShowContextMenu(), for example. To change it, provide your own and then
return S_TRUE.
Now create a function in you main code, somewhere:
<code>
Private Sub SetUIHandler()
' Get a handle to the ICustomDoc interface on the document
Dim icd As ICustomDoc
icd = CType(AxWebBrowser1.Document, ICustomDoc)
icd.SetUIHandler(New DocHostUIHandler)
' *** Make sure you wait for a readystate of DocumentComplete here ***
End Sub
</code>
Now, call SetUIHandler in the DocumentComplete event of the AxWebBrowser1.
Finally, going back to the class that implements IDocHostUIHandler, my
GetHostInfo does this:
<code>
With pInfo
.cbSize = Len(pInfo)
.dwFlags = DOCHOSTUIFLAG.DOCHOSTUIFLAG_DIV_BLOCKDEFAULT
.dwDoubleClick = DOCHOSTUIDBLCLK.DOCHOSTUIDBLCLK_DEFAULT
End With
</code>
You can set the flags to what you like, for example, one of them affects the
3D border. The definition of the flags is in the MSDN.
Well, that's it. I hope I've included everything. Let me know how you get
on.
HTH
Charles