Using AxWebBrowser in VB 2005

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doe

    #1

    Using AxWebBrowser in VB 2005

    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 RegisterAsBrows er
    and Application to get each instance of a browser working on each tab
    (and those methods are not available in 2005).

    I found some code on MSDN forums, but the extention didn't really cover
    RegisterAsBrows er. Someone told me how to do it, but it's in c and
    basically over my head. Even though he later added some VB code (<In>
    should be changed to <[In]>). I would need definitions for each
    OLECMD... and I couldn't figure out what to attach the interfaces to...

    http://forums.microsoft.com/MSDN/Sho...83565&SiteID=1...


    Sigh. So I figured, okay, this is a LOT OF TROUBLE just to make the
    "new" browser work like the "old" browser. So I'll just USE the "old"
    AxWebBrowser in 2005. Solves all my problems, code will work, will have
    RegisterAsBrows er. (Yes, someone on this group told me the browsers are
    basically the same just "wrapped" differently.)

    Dim ThisBrowser as New SHDocVw.AxWebBr owser

    Only I can't declare a new browser as AxWebBrowser. I get an error of
    AxWebBrowser ambigious in ShowDocVw namespace.

    I have references to both Interop.SHDocVw and AxInerop.SHDocV w in my
    project. But when I go into the form to do an Import, all I get is the
    SHDocVw namespace with no ability to add on dots and sub namespaces.

    What am I doing wrong? How can I do the right Imports and namespaces?
    How can I declare a new instance of an AxWebBrowser?

    This namespace stuff makes my head swim, actually. I am a fairly good
    programmer, but some of this VB.Net stuff is too convoluted.

    Any help appreciated as I stumble around in the dark.

    Doe

  • Colin Neller

    #2
    Re: Using AxWebBrowser in VB 2005

    > Okay, I've given up on using the "new" WebBrowser in 2005 to do what I[color=blue]
    > want to do -- tabbed browsing. It seems I really need RegisterAsBrows er
    > and Application to get each instance of a browser working on each tab
    > (and those methods are not available in 2005).[/color]

    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.W ebBrowser1.Acti veXInstance,
    IWebBrowser2)
    wb.RegisterAsBr owser = 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



    Comment

    • CMM

      #3
      Re: Using AxWebBrowser in VB 2005

      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(L ayoutKind.Seque ntial)> _
      Friend Structure OLECMDTEXT
      Public cmdtextf As UInt32
      Public cwActual As UInt32
      Public cwBuf As UInt32
      Public rgwz As Char
      End Structure

      <StructLayout(L ayoutKind.Seque ntial)> _
      Friend Structure OLECMD
      Public cmdID As Long
      Public cmdf As UInt64
      End Structure

      ' Interop definition for IOleCommandTarg et.
      <ComImport(), Guid("b722bccb-4e68-101b-a2bc-00aa00404770"),
      InterfaceType(C omInterfaceType .InterfaceIsIUn known)> _
      Friend Interface IOleCommandTarg et
      ' 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 IOleCommandTarg et interface from
      your
      ' app, it would translate into a call to QueryStatus() instead.
      Sub QueryStatus(ByR ef pguidCmdGroup As Guid, ByVal cCmds As UInt32,
      <MarshalAs(Unma nagedType.LPArr ay, 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 EnhancedWebBrow ser
      Inherits WebBrowser

      Private commandGuid As New Guid(&HED016940 , -17061, &H11CF, &HBA, &H4E,
      &H0, &HC0, &H4F, &HD7, &H8, &H16)

      Private Enum MiscCommandTarg et
      Find = 1
      ViewSource = 2
      End Enum

      Private ReadOnly Property UnderlyingBrows er() As SHDocVw.WebBrow ser

      Get
      Return CType(Me.Active XInstance, SHDocVw.WebBrow ser)
      End Get

      End Property

      Public Function IsEditCutEnable d() As Boolean

      Dim result As SHDocVw.OLECMDF =
      Me.UnderlyingBr owser.QueryStat usWB(SHDocVw.OL ECMDID.OLECMDID _CUT)

      Return ((result And SHDocVw.OLECMDF .OLECMDF_ENABLE D) =
      SHDocVw.OLECMDF .OLECMDF_ENABLE D)

      End Function

      Public Function IsEditCopyEnabl ed() As Boolean

      Dim result As SHDocVw.OLECMDF =
      Me.UnderlyingBr owser.QueryStat usWB(SHDocVw.OL ECMDID.OLECMDID _COPY)

      Return ((result And SHDocVw.OLECMDF .OLECMDF_ENABLE D) =
      SHDocVw.OLECMDF .OLECMDF_ENABLE D)

      End Function

      Public Function IsEditPasteEnab led() As Boolean

      Dim result As SHDocVw.OLECMDF =
      Me.UnderlyingBr owser.QueryStat usWB(SHDocVw.OL ECMDID.OLECMDID _PASTE)

      Return ((result And SHDocVw.OLECMDF .OLECMDF_ENABLE D) =
      SHDocVw.OLECMDF .OLECMDF_ENABLE D)

      End Function

      Public Function IsEditUndoEnabl ed() As Boolean

      Dim result As SHDocVw.OLECMDF =
      Me.UnderlyingBr owser.QueryStat usWB(SHDocVw.OL ECMDID.OLECMDID _UNDO)

      Return ((result And SHDocVw.OLECMDF .OLECMDF_ENABLE D) =
      SHDocVw.OLECMDF .OLECMDF_ENABLE D)

      End Function

      Public Sub ExecEditCut()

      Me.UnderlyingBr owser.ExecWB(SH DocVw.OLECMDID. OLECMDID_CUT,
      SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DONTPROMP TUSER)

      End Sub

      Public Sub ExecEditCopy()

      Me.UnderlyingBr owser.ExecWB(SH DocVw.OLECMDID. OLECMDID_COPY,
      SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DONTPROMP TUSER)

      End Sub

      Public Sub ExecEditPaste()

      Me.UnderlyingBr owser.ExecWB(SH DocVw.OLECMDID. OLECMDID_PASTE,
      SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DONTPROMP TUSER)

      End Sub

      Public Sub ExecEditUndo()

      Me.UnderlyingBr owser.ExecWB(SH DocVw.OLECMDID. OLECMDID_UNDO,
      SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DONTPROMP TUSER)

      End Sub

      Private Sub ExecOleCommandT arget(ByVal command As MiscCommandTarg et)

      Dim commandTarget As IOleCommandTarg et
      Dim obj As Object

      Try
      commandTarget = CType(Me.Docume nt.DomDocument,
      IOleCommandTarg et)
      commandTarget.E xec(commandGuid , command,
      SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DODEFAULT , obj, obj)
      Catch
      Throw (New Exception(Err.G etException().M essage))
      End Try

      End Sub

      Public Sub ShowFindDialog( )

      ExecOleCommandT arget(MiscComma ndTarget.Find)

      End Sub

      Public Sub ShowSource()

      ExecOleCommandT arget(MiscComma ndTarget.ViewSo urce)

      End Sub

      End Class





      --
      -C. Moya

      "Colin Neller" <cneller@gmail. com> wrote in message
      news:OonqjqTSGH A.5108@TK2MSFTN GP09.phx.gbl...[color=blue][color=green]
      >> 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 RegisterAsBrows er
      >> and Application to get each instance of a browser working on each tab
      >> (and those methods are not available in 2005).[/color]
      >
      > 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.W ebBrowser1.Acti veXInstance,
      > IWebBrowser2)
      > wb.RegisterAsBr owser = 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
      >[/color]


      Comment

      • Doe

        #4
        Re: Using AxWebBrowser in VB 2005

        Thanks, Colin, I was wondering if a Direct Cast was possible. I have
        found code for IWebBrowser2.

        Thanks, C. Moya. Very nice, but I already have code for stuff like Find
        and Copy/Paste in both 2003 and 2005. Need the RegisterAsBrows er. And
        have already found those definitions for OLECMDTEXT and OLECMD. Need
        the others that Colin mentioned.

        Thanks for the replies, guys. Going to try Colin's suggest and see if
        it works. Will report back. A Direct Cast just might do it.

        Later, Doe

        Comment

        • CMM

          #5
          Re: Using AxWebBrowser in VB 2005

          You should have looked more closely. From within the inherited "extended"
          WebBrowser class I posted...

          Me.UnderlyingBr owser.RegisterA sBrowser = True

          The code for "UnderlyingBrow ser" is simply:

          Public ReadOnly Property UnderlyingBrows er() As SHDocVw.WebBrow ser

          Get
          Return CType(Me.Active XInstance, SHDocVw.WebBrow ser)
          End Get

          End Property


          --
          -C. Moya

          "Doe" <doeadeer3@aol. com> wrote in message
          news:1142606629 .667008.236350@ u72g2000cwu.goo glegroups.com.. .[color=blue]
          > Thanks, Colin, I was wondering if a Direct Cast was possible. I have
          > found code for IWebBrowser2.
          >
          > Thanks, C. Moya. Very nice, but I already have code for stuff like Find
          > and Copy/Paste in both 2003 and 2005. Need the RegisterAsBrows er. And
          > have already found those definitions for OLECMDTEXT and OLECMD. Need
          > the others that Colin mentioned.
          >
          > Thanks for the replies, guys. Going to try Colin's suggest and see if
          > it works. Will report back. A Direct Cast just might do it.
          >
          > Later, Doe
          >[/color]


          Comment

          • Doe

            #6
            Re: Using AxWebBrowser in VB 2005

            Cool.

            Doe

            Comment

            • CMM

              #7
              Re: Using AxWebBrowser in VB 2005

              Clarification to previous post (read it first):
              Actually I made UnderlyingBrows er private to the class... you can easily
              make it public and expose it or make a new wrapper property for
              RegisterAsBrows er as so:

              Public Property RegisterAsBrows er() As Boolean
              Get
              Return Me.UnderlyingBr owser.RegisterA sBrowser
              End Get
              Set(ByVal value As Boolean)
              Me.UnderlyingBr owser.RegisterA sBrowser = value
              End Set
              End Property


              --
              -C. Moya

              "CMM" <cmm@nospam.com > wrote in message
              news:OFe7TPdSGH A.1948@TK2MSFTN GP09.phx.gbl...[color=blue]
              > You should have looked more closely. From within the inherited "extended"
              > WebBrowser class I posted...
              >
              > Me.UnderlyingBr owser.RegisterA sBrowser = True
              >
              > The code for "UnderlyingBrow ser" is simply:
              >
              > Public ReadOnly Property UnderlyingBrows er() As SHDocVw.WebBrow ser
              >
              > Get
              > Return CType(Me.Active XInstance, SHDocVw.WebBrow ser)
              > End Get
              >
              > End Property
              >
              >
              > --
              > -C. Moya
              > www.cmoya.com
              > "Doe" <doeadeer3@aol. com> wrote in message
              > news:1142606629 .667008.236350@ u72g2000cwu.goo glegroups.com.. .[color=green]
              >> Thanks, Colin, I was wondering if a Direct Cast was possible. I have
              >> found code for IWebBrowser2.
              >>
              >> Thanks, C. Moya. Very nice, but I already have code for stuff like Find
              >> and Copy/Paste in both 2003 and 2005. Need the RegisterAsBrows er. And
              >> have already found those definitions for OLECMDTEXT and OLECMD. Need
              >> the others that Colin mentioned.
              >>
              >> Thanks for the replies, guys. Going to try Colin's suggest and see if
              >> it works. Will report back. A Direct Cast just might do it.
              >>
              >> Later, Doe
              >>[/color]
              >
              >[/color]


              Comment

              • Doe

                #8
                Re: Using AxWebBrowser in VB 2005

                Okay, there is something I am not understanding here. I finally got
                around to testing this. When I try it, calling RegisterAsBrows er, I get
                an error message -- must use new keyword.

                I am doing:
                Dim ThisBrowser As EnhancedWebBrow ser

                ThisBrowser = New EnhancedWebBrow ser
                ThisBrowser.Und erlyingBrowser. RegisterAsBrows er = True

                But somehow there must also be a New required for the Underlying
                Browser, to create a new instance.

                Right? Should that be put in the Class, Public Sub New?

                Sigh. Sorry to be such a dunce.

                Doe

                Comment

                Working...