Imports System.Runtime.InteropServices
Imports mshtml
Public Class Form1
WithEvents Browser As New ExWebBrowser
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Browser.Dock = DockStyle.Fill
Me.Controls.Add(Browser)
Browser.GoHome()
End Sub
End Class
Public Class ExWebBrowser
Inherits WebBrowser
Sub New()
MyBase.New()
End Sub
Protected Overrides Function CreateWebBrowserSiteBase() _
As System.Windows.Forms.WebBrowserSiteBase
Return New ExWebBrowserSite(Me)
End Function
Protected Class ExWebBrowserSite
Inherits WebBrowser.WebBrowserSite
Implements IDocHostUIHandler
Sub New(ByVal host As WebBrowser)
MyBase.New(host)
End Sub
Public Sub EnableModeless(ByVal fEnable As Integer) _
Implements IDocHostUIHandler.EnableModeless
End Sub
Public Function FilterDataObject( _
ByVal pDO As System.Windows.Forms.IDataObject) _
As System.Windows.Forms.IDataObject _
Implements IDocHostUIHandler.FilterDataObject
Return pDO
End Function
Public Function GetDropTarget( _
ByVal pDropTarget As System.Windows.Forms.IDropTarget) _
As System.Windows.Forms.IDropTarget _
Implements IDocHostUIHandler.GetDropTarget
Return pDropTarget
End Function
Public Function GetExternal() As Object _
Implements IDocHostUIHandler.GetExternal
Return Nothing
End Function
Public Sub GetHostInfo(ByRef theHostUIInfo As DOCHOSTUIINFO) _
Implements IDocHostUIHandler.GetHostInfo
End Sub
Public Sub GetOptionKeyPath(ByRef pchKey As String, _
ByVal dw As Integer) Implements IDocHostUIHandler.GetOptionKeyPath
End Sub
Public Sub HideUI() Implements IDocHostUIHandler.HideUI
End Sub
Public Sub OnDocWindowActivate(ByVal fActivate As Integer) _
Implements IDocHostUIHandler.OnDocWindowActivate
End Sub
Public Sub OnFrameWindowActivate(ByVal fActivate As Integer) _
Implements IDocHostUIHandler.OnFrameWindowActivate
End Sub
Public Sub ResizeBorder(ByRef prcBorder As mshtml.tagRECT, _
ByVal pUIWindow As Integer, ByVal fFrameWindow As Integer) _
Implements IDocHostUIHandler.ResizeBorder
End Sub
Public Function ShowContextMenu(ByVal dwID As Integer, _
ByRef ppt As mshtml.tagPOINT, ByVal pcmdtReserved _
As IOleCommandTarget, ByVal pdispReserved As Object) _
As Integer Implements IDocHostUIHandler.ShowContextMenu
End Function
Public Sub ShowUI(ByVal dwID As Integer, _
ByRef pActiveObject As Object, _
ByRef pCommandTarget As IOleCommandTarget, _
ByRef pFrame As Object, ByRef pDoc As Object) _
Implements IDocHostUIHandler.ShowUI
End Sub
Public Function TranslateAccelerator(ByRef lpMsg As tagMSG, _
ByRef pguidCmdGroup As System.Guid, ByVal nCmdID As Integer) _
As Integer Implements IDocHostUIHandler.TranslateAccelerator
Const WM_KEYDOWN As Integer = &H100
Const S_FALSE As Integer = &H1
Const S_OK As Integer = &H0
If lpMsg.message = WM_KEYDOWN Then
If (Control.ModifierKeys And Keys.Control) = Keys.Control Then
Dim keyCode As Byte = CByte(lpMsg.wParam And &HFF)
If keyCode = Keys.N Then
Debug.Print("Ctrl-Nが押された")
Return S_OK
End If
End If
End If
Return S_FALSE
End Function
Public Function TranslateUrl(ByVal dwTranslate As Integer, _
ByVal pchURLIn As Integer) As Integer _
Implements IDocHostUIHandler.TranslateUrl
End Function
Public Sub UpdateUI() Implements IDocHostUIHandler.UpdateUI
End Sub
End Class
End Class
<StructLayout(LayoutKind.Sequential)> _
Public Structure DOCHOSTUIINFO
Public cbSize As Integer
Public dwFlags As Integer
Public dwDoubleClick As Integer
<MarshalAs(UnmanagedType.BStr)> Public pchHostCss As String
<MarshalAs(UnmanagedType.BStr)> Public pchHostNS As String
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=4)> _
Public Structure tagMSG
Public hwnd As IntPtr
Public message As Integer
Public wParam As Integer
Public lParam As Integer
Public time As Integer
Public pt As tagPOINT
End Structure
<ComImport(), _
ComVisible(False), _
Guid("BD3F23C0-D43E-11CF-893B-00AA00BDCE1A"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IDocHostUIHandler
<PreserveSig()> Function ShowContextMenu( _
ByVal dwID As Integer, _
ByRef ppt As tagPOINT, _
ByVal pcmdtReserved As IOleCommandTarget, _
<MarshalAs(UnmanagedType.IDispatch)> ByVal pdispReserved As Object _
) As Integer
Sub GetHostInfo(ByRef theHostUIInfo As DOCHOSTUIINFO)
Sub ShowUI(ByVal dwID As Integer, _
ByRef pActiveObject As Object, _
ByRef pCommandTarget As IOleCommandTarget, _
ByRef pFrame As Object, _
ByRef pDoc As Object)
Sub HideUI()
Sub UpdateUI()
Sub EnableModeless(ByVal fEnable As Integer)
Sub OnDocWindowActivate(ByVal fActivate As Integer)
Sub OnFrameWindowActivate(ByVal fActivate As Integer)
Sub ResizeBorder(ByRef prcBorder As tagRECT, _
ByVal pUIWindow As Integer, ByVal fFrameWindow As Integer)
<PreserveSig()> Function TranslateAccelerator( _
ByRef lpMsg As tagMSG, _
ByRef pguidCmdGroup As Guid, _
ByVal nCmdID As Integer _
) As Integer
Sub GetOptionKeyPath(<MarshalAs(UnmanagedType.BStr)> _
ByRef pchKey As String, ByVal dw As Integer)
Function GetDropTarget(ByVal pDropTarget As IDropTarget) As IDropTarget
Function GetExternal() As <MarshalAs(UnmanagedType.IDispatch)> Object
Function TranslateUrl(ByVal dwTranslate As Integer, _
ByVal pchURLIn As Integer) As Integer
Function FilterDataObject(ByVal pDO As IDataObject) As IDataObject
End Interface
<ComImport(), _
ComVisible(False), _
Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleCommandTarget
<PreserveSig()> Function QueryStatus( _
ByVal pguidCmdGroup As Guid, _
ByVal cCmds As Integer, _
<MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=1)> _
ByRef prgCmds As OLECMD(), _
ByRef CmdText As OLECMDTEXT _
) As Integer
<PreserveSig()> Function Exec( _
ByRef pguidCmdGroup As Guid, _
ByVal nCmdId As Integer, _
ByVal nCmdExecOpt As Integer, _
ByRef pvaIn As Object, _
ByRef pvaOut As Object _
) As Integer
End Interface
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure OLECMDTEXT
Public cmdtextf As Integer
Public cwActual As Integer
Public cwBuf As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=100)> Public rgwz As Char
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure OLECMD
Public cmdID As Integer
Public cmdf As Integer
End Structure
|