Hopefully this will get you started... my nice little webbrowser inherited
from VS2005's webbrowser to add missing functionality. You need to add a
reference to Microsoft Internet Controls COM object.
Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential)> _
Friend Structure OLECMDTEXT
Public cmdtextf As UInt32
Public cwActual As UInt32
Public cwBuf As UInt32
Public rgwz As Char
End Structure
<StructLayout(LayoutKind.Sequential)> _
Friend Structure OLECMD
Public cmdID As Long
Public cmdf As UInt64
End Structure
' Interop definition for IOleCommandTarget.
<ComImport(), Guid("b722bccb-4e68-101b-a2bc-00aa00404770"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )> _
Friend Interface IOleCommandTarget
' IMPORTANT: The order of the methods is critical here. We're going to
' perform early binding in most cases, so the order of the methods
' here MUST match the order of their vtable layout (which is determined
' by their layout in IDL). The interop calls key off the vtable
ordering,
' not the symbolic names, so if you switched these method declarations
' and attempted to call Exec() on an IOleCommandTarget interface from
your
' app, it would translate into a call to QueryStatus() instead.
Sub QueryStatus(ByRef pguidCmdGroup As Guid, ByVal cCmds As UInt32,
<MarshalAs(UnmanagedType.LPArray, SizeParamIndex:=1)> ByVal prgCmds As
OLECMD, ByRef pCmdText As OLECMDTEXT)
Sub Exec(ByRef pguidCmdGroup As Guid, ByVal nCmdId As Long, ByVal
nCmdExecOpt As Long, ByRef pvaIn As Object, ByRef pvaOut As Object)
End Interface
''' <summary>
''' Inherited from .NET 2.0 Webbrowser to provide missing functionality.
''' </summary>
''' <remarks>Even the new .NET 2.0 Webbrowser doesn't implement a full
feature set... this class begins to solve that.</remarks>
Public Class EnhancedWebBrowser
Inherits WebBrowser
Private commandGuid As New Guid(&HED016940, -17061, &H11CF, &HBA, &H4E,
&H0, &HC0, &H4F, &HD7, &H8, &H16)
Private Enum MiscCommandTarget
Find = 1
ViewSource = 2
End Enum
Private ReadOnly Property UnderlyingBrowser() As SHDocVw.WebBrowser
Get
Return CType(Me.ActiveXInstance, SHDocVw.WebBrowser)
End Get
End Property
Public Function IsEditCutEnabled() As Boolean
Dim result As SHDocVw.OLECMDF =
Me.UnderlyingBrowser.QueryStatusWB(SHDocVw.OLECMDI D.OLECMDID_CUT)
Return ((result And SHDocVw.OLECMDF.OLECMDF_ENABLED) =
SHDocVw.OLECMDF.OLECMDF_ENABLED)
End Function
Public Function IsEditCopyEnabled() As Boolean
Dim result As SHDocVw.OLECMDF =
Me.UnderlyingBrowser.QueryStatusWB(SHDocVw.OLECMDI D.OLECMDID_COPY)
Return ((result And SHDocVw.OLECMDF.OLECMDF_ENABLED) =
SHDocVw.OLECMDF.OLECMDF_ENABLED)
End Function
Public Function IsEditPasteEnabled() As Boolean
Dim result As SHDocVw.OLECMDF =
Me.UnderlyingBrowser.QueryStatusWB(SHDocVw.OLECMDI D.OLECMDID_PASTE)
Return ((result And SHDocVw.OLECMDF.OLECMDF_ENABLED) =
SHDocVw.OLECMDF.OLECMDF_ENABLED)
End Function
Public Function IsEditUndoEnabled() As Boolean
Dim result As SHDocVw.OLECMDF =
Me.UnderlyingBrowser.QueryStatusWB(SHDocVw.OLECMDI D.OLECMDID_UNDO)
Return ((result And SHDocVw.OLECMDF.OLECMDF_ENABLED) =
SHDocVw.OLECMDF.OLECMDF_ENABLED)
End Function
Public Sub ExecEditCut()
Me.UnderlyingBrowser.ExecWB(SHDocVw.OLECMDID.OLECM DID_CUT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER )
End Sub
Public Sub ExecEditCopy()
Me.UnderlyingBrowser.ExecWB(SHDocVw.OLECMDID.OLECM DID_COPY,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER )
End Sub
Public Sub ExecEditPaste()
Me.UnderlyingBrowser.ExecWB(SHDocVw.OLECMDID.OLECM DID_PASTE,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER )
End Sub
Public Sub ExecEditUndo()
Me.UnderlyingBrowser.ExecWB(SHDocVw.OLECMDID.OLECM DID_UNDO,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER )
End Sub
Private Sub ExecOleCommandTarget(ByVal command As MiscCommandTarget)
Dim commandTarget As IOleCommandTarget
Dim obj As Object
Try
commandTarget = CType(Me.Document.DomDocument,
IOleCommandTarget)
commandTarget.Exec(commandGuid, command,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, obj, obj)
Catch
Throw (New Exception(Err.GetException().Message))
End Try
End Sub
Public Sub ShowFindDialog()
ExecOleCommandTarget(MiscCommandTarget.Find)
End Sub
Public Sub ShowSource()
ExecOleCommandTarget(MiscCommandTarget.ViewSource)
End Sub
End Class
--
-C. Moya
www.cmoya.com
"Colin Neller" <cn*****@gmail.com> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...
Okay, I've given up on using the "new" WebBrowser in 2005 to do what I
want to do -- tabbed browsing. It seems I really need RegisterAsBrowser
and Application to get each instance of a browser working on each tab
(and those methods are not available in 2005).
I would recommend you try the 2005 WB again. What you're trying to do
should pretty straight forward:
Dim wb As IWebBrowser2 = DirectCast(Me.WebBrowser1.ActiveXInstance,
IWebBrowser2)
wb.RegisterAsBrowser = True
The slightly tricky part would be defining IWebBrowser2... just do a
search on http://www.pinvoke.net/ and then just copy and paste. You will
need to get the definitions to the following:
IWebBrowser2
OLECMDID
OLECMDEXCOPT
OLECMDF
tagREADYSTATE
--
Colin Neller
http://www.colinneller.com/blog