Using Web Browser Control in VB .net

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

    #1

    Using Web Browser Control in VB .net

    Hi,
    Iam a newbie to dotnet and I experience problems in using the Browser
    control in VB .net. Though Iam able to use it with its basic features,
    I need to customise it.


    The above link shows where what I want is achived in C#, but I need t
    oa cjhive the same in VB .net.

    Someone help and guidance would be much appreciated.

    Regards
    GOkul
  • Charles Law

    #2
    Re: Using Web Browser Control in VB .net

    Gokul

    The web page you referenced comes back with an error for me. Can you check
    it and re-post. Also, can you be more specific about the kind of problems
    you are having?

    Charles


    "gokul" <gokulrajad@yah oo.com> wrote in message
    news:c1f374f7.0 307312221.92afa 13@posting.goog le.com...[color=blue]
    > Hi,
    > Iam a newbie to dotnet and I experience problems in using the Browser
    > control in VB .net. Though Iam able to use it with its basic features,
    > I need to customise it.
    >
    > http://www.codeproject.com/books/0764549146_8.asp
    > The above link shows where what I want is achived in C#, but I need t
    > oa cjhive the same in VB .net.
    >
    > Someone help and guidance would be much appreciated.
    >
    > Regards
    > GOkul[/color]


    Comment

    • Gokul RajaD

      #3
      Re: Using Web Browser Control in VB .net

      Hi Charles Law,
      Iam a newbie to dotnet and I experience problems in using the Browser
      control in VB .net.
      Though Iam able to use it with its basic features,
      I need to customise it.



      The above links works perfectly....fi ne for me...please try copying and
      pasting the link in the browser.
      check the HTML customisation part....
      Listing 8-36:: The Complete Code for MainForm of MyCustomWebBrow ser

      This is the code which I need in VB.Net.
      Regards
      Gokul



      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Charles Law

        #4
        Re: Using Web Browser Control in VB .net

        Hi Gokul

        I can see the code you are referring to. There is a lot there, and much of
        it can be achieved with the WebBrowser control directly, without any special
        effort.

        You say you are able to use it with basic features, so I am not sure which
        ones are causing you problems. Rather than trawl through the listing, can
        you identify some of the specific problems you are having? For example, to
        print you would use

        AxWebBrowser1.E xecWB(OLECMDID_ PRINT, OLECMDEXECOPT_P ROMPTUSER)

        Alternatively, are you trying to show a custom context menu with the
        IDocHostUIHandl er interface, or is it something else?

        Regards

        Charles


        "Gokul RajaD" <grdin@rediffma il.com> wrote in message
        news:OAzITBeWDH A.656@tk2msftng p13.phx.gbl...[color=blue]
        > Hi Charles Law,
        > Iam a newbie to dotnet and I experience problems in using the Browser
        > control in VB .net.
        > Though Iam able to use it with its basic features,
        > I need to customise it.
        >
        > http://www.codeproject.com/books/0764549146_8.asp
        >
        > The above links works perfectly....fi ne for me...please try copying and
        > pasting the link in the browser.
        > check the HTML customisation part....
        > Listing 8-36:: The Complete Code for MainForm of MyCustomWebBrow ser
        >
        > This is the code which I need in VB.Net.
        > Regards
        > Gokul
        >
        >
        >
        > *** Sent via Developersdex http://www.developersdex.com ***
        > Don't just participate in USENET...get rewarded for it![/color]


        Comment

        • gokul

          #5
          Re: Using Web Browser Control in VB .net

          Dear Charles Law,
          I need to remove the 3D border of the Webbrowser control, they say it
          could be achieved using IDocHostUIHandl er.

          and also Iam trying to change the Context menu.
          Apart from it Iam trying to capture the word/text on which the mouse
          is pointing using API calls.....do u have any idea about it!!!!?

          Thank You for the prompt replies.

          Letz work on it to make a wonderful product and share the Concepts and
          ideas.
          Regards
          Gokul

          Comment

          • Charles Law

            #6
            Re: Using Web Browser Control in VB .net

            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_D IALOG = &H1
            DOCHOSTUIFLAG_D ISABLE_HELP_MEN U = &H2
            DOCHOSTUIFLAG_N O3DBORDER = &H4
            DOCHOSTUIFLAG_S CROLL_NO = &H8
            DOCHOSTUIFLAG_D ISABLE_SCRIPT_I NACTIVE = &H10
            DOCHOSTUIFLAG_O PENNEWWIN = &H20
            DOCHOSTUIFLAG_D ISABLE_OFFSCREE N = &H40
            DOCHOSTUIFLAG_F LAT_SCROLLBAR = &H80
            DOCHOSTUIFLAG_D IV_BLOCKDEFAULT = &H100
            DOCHOSTUIFLAG_A CTIVATE_CLIENTH IT_ONLY = &H200
            DOCHOSTUIFLAG_O VERRIDEBEHAVIOR FACTORY = &H400
            DOCHOSTUIFLAG_C ODEPAGELINKEDFO NTS = &H800
            DOCHOSTUIFLAG_U RL_ENCODING_DIS ABLE_UTF8 = &H1000
            DOCHOSTUIFLAG_U RL_ENCODING_ENA BLE_UTF8 = &H2000
            DOCHOSTUIFLAG_E NABLE_FORMS_AUT OCOMPLETE = &H4000
            DOCHOSTUIFLAG_E NABLE_INPLACE_N AVIGATION = &H10000
            DOCHOSTUIFLAG_I ME_ENABLE_RECON VERSION = &H20000
            DOCHOSTUIFLAG_T HEME = &H40000
            DOCHOSTUIFLAG_N OTHEME = &H80000
            DOCHOSTUIFLAG_N OPICS = &H100000
            DOCHOSTUIFLAG_N O3DOUTERBORDER = &H200000
            End Enum

            Public Enum DOCHOSTUIDBLCLK
            DOCHOSTUIDBLCLK _DEFAULT = 0
            DOCHOSTUIDBLCLK _SHOWPROPERTIES = 1
            DOCHOSTUIDBLCLK _SHOWCODE = 2
            End Enum

            ' MSG structure
            <StructLayout(L ayoutKind.Seque ntial)> _
            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(L ayoutKind.Seque ntial)> _
            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

            ' OLEMENUGROUPWID THS structure
            <StructLayout(L ayoutKind.Seque ntial)> _
            Public Structure OLEMENUGROUPWID THS
            <MarshalAs(Unma nagedType.ByVal Array, SizeConst:=6)> _
            Dim width() As Integer
            End Structure

            ' ICustomDoc interface
            <ComVisible(Tru e), ComImport(),
            Guid("3050f3f0-98b5-11cf-bb82-00aa00bdce0b"), _
            InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
            Public Interface ICustomDoc
            Sub SetUIHandler(By Val pUIHandler As IDocHostUIHandl er)
            End Interface

            ' IOleWindow interface
            <ComVisible(Tru e), ComImport(),
            Guid("00000114-0000-0000-C000-000000000046"), _
            InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
            Public Interface IOleWindow
            Sub GetWindow(ByVal phwnd As IntPtr)
            Sub ContextSensitiv eHelp(ByVal fEnterMode As Boolean)
            End Interface

            ' IOleInPlaceActi veObject interface
            <ComVisible(Tru e), ComImport(),
            Guid("00000117-0000-0000-C000-000000000046"), _
            InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
            Public Interface IOleInPlaceActi veObject : Inherits IOleWindow
            ' IOleWindow interface
            Shadows Sub GetWindow(ByVal phwnd As IntPtr)
            Shadows Sub ContextSensitiv eHelp(ByVal fEnterMode As Boolean)
            Sub TranslateAccele rator(ByRef lpmsg As MSG)
            Sub OnFrameWindowAc tivate(ByVal fActivate As Boolean)
            Sub OnDocWindowActi vate(ByVal fActivate As Boolean)
            Sub ResizeBorder(By Ref prcBorder As tagRECT, ByVal pUIWindow As
            IOleInPlaceUIWi ndow, ByVal fFrameWindow As Boolean)
            Sub EnableModeless( ByVal fEnable As Boolean)
            End Interface

            ' IOleInPlaceUIWi ndow interface
            <ComVisible(Tru e), ComImport(),
            Guid("00000115-0000-0000-C000-000000000046"), _
            InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
            Public Interface IOleInPlaceUIWi ndow : Inherits IOleWindow
            ' IOleWindow interface
            Shadows Sub GetWindow(ByVal phwnd As IntPtr)
            Shadows Sub ContextSensitiv eHelp(ByVal fEnterMode As Boolean)
            Sub GetBorder(ByRef lprectBorder As tagRECT)
            Sub RequestBorderSp ace(ByRef pborderwidths As tagRECT)
            Sub SetBorderSpace( ByRef pborderwidths As tagRECT)
            Sub SetActiveObject (ByVal pActiveObject As IOleInPlaceActi veObject,
            ByVal pszObjName As String)
            End Interface

            ' IDropTarget interface
            <ComVisible(Tru e), ComImport(),
            Guid("00000122-0000-0000-C000-000000000046"), _
            InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
            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

            ' IOleInPlaceFram e interface
            <ComVisible(Tru e), ComImport(),
            Guid("00000116-0000-0000-C000-000000000046"), _
            InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
            Public Interface IOleInPlaceFram e : Inherits IOleInPlaceUIWi ndow
            ' IOleWindow interface
            Shadows Sub GetWindow(ByVal phwnd As IntPtr)
            Shadows Sub ContextSensitiv eHelp(ByVal fEnterMode As Boolean)

            ' IOleInPlaceUIWi ndow interface
            Shadows Sub GetBorder(ByRef lprectBorder As tagRECT)
            Shadows Sub RequestBorderSp ace(ByRef pborderwidths As tagRECT)
            Shadows Sub SetBorderSpace( ByRef pborderwidths As tagRECT)
            Shadows Sub SetActiveObject (ByVal pActiveObject As
            IOleInPlaceActi veObject, ByVal pszObjName As String)

            ' TODO: hmenuShared should be a reference to a remotable handle
            Sub InsertMenus(ByV al hmenuShared As IntPtr, ByRef lpMenuWidths As
            OLEMENUGROUPWID THS)
            Sub SetMenu(ByVal hmenuShared As IntPtr, ByVal holemenu As IntPtr, ByVal
            hwndActiveObjec t As IntPtr)
            Sub RemoveMenus(ByV al hmenuShared As IntPtr)
            Sub SetStatusText(B yVal pszStatusText As String)
            Sub EnableModeless( ByVal fEnable As Boolean)
            Sub TranslateAccele rator(ByRef lpmsg As MSG, ByVal wID As UInt16)
            End Interface

            ' IDocHostUIHandl er interface
            <ComVisible(Tru e), ComImport(),
            Guid("bd3f23c0-d43e-11cf-893b-00aa00bdce1a"), _
            InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIUnknown) > _
            Public Interface IDocHostUIHandl er

            <PreserveSig( )> _
            Function ShowContextMenu ( _
            ByVal dwID As Integer, _
            ByRef ppt As tagPOINT, _
            <MarshalAs(Unma nagedType.IUnkn own)> ByVal pcmdtReserved As Object, _
            <MarshalAs(Unma nagedType.IDisp atch)> ByVal pdispReserved As Object)
            As Integer

            Sub GetHostInfo(ByR ef pInfo As DOCHOSTUIINFO)

            <PreserveSig( )> _
            Function ShowUI( _
            ByVal dwID As Integer, _
            ByVal pActiveObject As IOleInPlaceActi veObject, _
            ByVal pCommandTarget As IOleCommandTarg et, _
            ByVal pFrame As IOleInPlaceFram e, _
            ByVal pDoc As IOleInPlaceUIWi ndow) As Integer

            Sub HideUI()
            Sub UpdateUI()
            Sub EnableModeless( ByVal fEnable As Boolean)
            Sub OnDocWindowActi vate(ByVal fActivate As Boolean)
            Sub OnFrameWindowAc tivate(ByVal fActivate As Boolean)

            Sub ResizeBorder( _
            ByRef prcBorder As tagRECT, _
            ByVal pUIWindow As IOleInPlaceUIWi ndow, _
            ByVal fFrameWindow As Boolean)

            <PreserveSig( )> _
            Function TranslateAccele rator( _
            ByRef lpMsg As MSG, _
            ByRef pguidCmdGroup As Guid, _
            ByVal nCmdID As Integer) As Integer

            Sub GetOptionKeyPat h( _
            ByRef pchKey As String, _
            ByVal dw As Integer)

            Sub GetDropTarget( _
            ByVal pDropTarget As IDropTarget, _
            ByRef ppDropTarget As IDropTarget)

            Sub GetExternal(<Ma rshalAs(Unmanag edType.IDispatc h)> ByRef ppDispatch As
            Object)

            <PreserveSig( )> _
            Function TranslateUrl( _
            ByVal dwTranslate As Integer, _
            ByRef pchURLIn As UInt16, _
            ByVal ppchURLOut As IntPtr) As Integer

            <PreserveSig( )> _
            Function FilterDataObjec t( _
            ByVal pDO As IDataObject, _
            ByRef ppDORet As IDataObject) As Integer

            End Interface
            </code>

            Next, create a class (I call mine DocHostUIHandle r) and implement
            IDocHostUIHandl er. 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(AxWebBrow ser1.Document, ICustomDoc)
            icd.SetUIHandle r(New DocHostUIHandle r)

            ' *** Make sure you wait for a readystate of DocumentComplet e here ***

            End Sub
            </code>

            Now, call SetUIHandler in the DocumentComplet e event of the AxWebBrowser1.

            Finally, going back to the class that implements IDocHostUIHandl er, my
            GetHostInfo does this:

            <code>
            With pInfo
            .cbSize = Len(pInfo)
            .dwFlags = DOCHOSTUIFLAG.D OCHOSTUIFLAG_DI V_BLOCKDEFAULT
            .dwDoubleClick = DOCHOSTUIDBLCLK .DOCHOSTUIDBLCL K_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


            "gokul" <gokulrajad@yah oo.com> wrote in message
            news:c1f374f7.0 308060735.30a9c 829@posting.goo gle.com...[color=blue]
            > Dear Charles Law,
            > I need to remove the 3D border of the Webbrowser control, they say it
            > could be achieved using IDocHostUIHandl er.
            >
            > and also Iam trying to change the Context menu.
            > Apart from it Iam trying to capture the word/text on which the mouse
            > is pointing using API calls.....do u have any idea about it!!!!?
            >
            > Thank You for the prompt replies.
            >
            > Letz work on it to make a wonderful product and share the Concepts and
            > ideas.
            > Regards
            > Gokul[/color]


            Comment

            • Charles Law

              #7
              Re: Using Web Browser Control in VB .net

              Hi Gokul


              When you say you could not implement GetHostInfo, did you get an error, or
              did it just not work?

              Here is my version of GetHostInfo:

              <code>
              Public Sub GetHostInfo(ByR ef pInfo As DOCHOSTUIINFO) Implements
              IDocHostUIHandl er.GetHostInfo

              With pInfo
              .cbSize = Len(pInfo)
              .dwFlags = DOCHOSTUIFLAG.D OCHOSTUIFLAG_DI V_BLOCKDEFAULT Or _
              DOCHOSTUIFLAG.D OCHOSTUIFLAG_FL AT_SCROLLBAR Or _
              DOCHOSTUIFLAG.D OCHOSTUIFLAG_NO 3DBORDER

              .dwDoubleClick = DOCHOSTUIDBLCLK .DOCHOSTUIDBLCL K_DEFAULT
              End With

              End Sub
              <code>

              This successfully removes the 3D border, and also gives me a flat scroll
              bar.

              For additional information, I am using Windows 2000, SP4 and VS2003

              Regards

              Charles


              "gokul" <gokulrajad@yah oo.com> wrote in message
              news:c1f374f7.0 308070817.486a0 335@posting.goo gle.com...[color=blue]
              > Hi Charles,
              > Thank you for a wonderful reply.
              > I was able to implement your code, but stuck half the way......I
              > implemented the Context Menu but Iam unable to implement
              > GetHostInfo.... .to remove 3D borders.....cou ld you please send me a
              > code snippet.
              >
              > Not to forget the smile :) it brought, when the code was working.....
              > Thanks for it once again.
              >
              >
              > Regards
              > Gokul Raja.D[/color]


              Comment

              • gokul

                #8
                Re: Using Web Browser Control in VB .net

                Hi Charles,

                By the time I replied U sat on it to give a last shot..........a nd
                made it to work after a couple of tweaks......... ......

                Its pretty fine.......now. ....

                Thank You

                Regards
                Gokul Raja.D

                Comment

                • gokul

                  #9
                  Re: Using Web Browser Control in VB .net

                  The tweaks are:

                  1.
                  These Interface(IOleC ommandTarget) were missing and it gave an error
                  during Compilation, so I added this code:
                  <code>
                  <StructLayout(L ayoutKind.Seque ntial)> _
                  Public 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)> _
                  Public 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)> _
                  Public Interface IOleCommandTarg et
                  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
                  </code>

                  2. During the first time the Noborder or FlatScroll..... none of the
                  setting were taking place only we load it again it got
                  implemented...s o just triggered as follows:
                  AxWebBrowser1.N avigate("about: blank")
                  AxWebBrowser1.N avigate("http://www.google.com" )

                  So this tweak allowed to achieve the desired effect on the Control
                  during load itself......... ..
                  It works pretty fine now......
                  Regards
                  Gokul Raja.D

                  Comment

                  • Charles Law

                    #10
                    Re: Using Web Browser Control in VB .net

                    Hi Gokul

                    Yes, sorry for missing those out. I have included mine below. They are
                    different in some places. It won't make any difference to you at this stage,
                    but I would suggest changing them because it will make a difference if you
                    use the IOLECommandTarg et interface in future. In particular, the 'longs'
                    translate to integers in .NET.

                    <code>
                    ' OLECMD
                    <StructLayout(L ayoutKind.Seque ntial)> _
                    Public Structure OLECMD
                    Public cmdID As Int32
                    Public cmdf As Int32
                    End Structure

                    ' OLECMDTEXT
                    <StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.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(Unma nagedType.ByVal TStr, SizeConst:=256) > _
                    Public text As String
                    End Class

                    ' IOleCommandTarg et interface
                    <ComImport(), Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), _
                    InterfaceType(C omInterfaceType .InterfaceIsIUn known)> _
                    Public Interface IOleCommandTarg et

                    Sub QueryStatus(ByR ef pguidCmdGroup As Guid, ByVal cCmds As Int32, _
                    <InAttribute( ), Out(), MarshalAs(Unman agedType.LPArra y,
                    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>

                    Also, I would recommend putting a wait after every navigate. I call a
                    function WaitReady(), below

                    <code>
                    Private Sub WaitReady()
                    Do Until AxWebBrowser1.R eadyState =
                    SHDocVw.tagREAD YSTATE.READYSTA TE_COMPLETE
                    Application.DoE vents()
                    Loop
                    End Sub
                    </code>

                    You could probably dispense with the second navigate then.

                    The reason for the wait is that pages are loaded asynchronously. Therefore,
                    the first navigate returns immediately, even before the page has been
                    initialised. The second navigate then causes the first one to be cancelled,
                    and the second page gets loaded.

                    As a general rule, before doing anything else, always navigate to
                    about:blank and wait for complete. This ensures that the control is always
                    fully initialised before you proceed.

                    HTH

                    Charles


                    "gokul" <gokulrajad@yah oo.com> wrote in message
                    news:c1f374f7.0 308072048.3d1d9 f23@posting.goo gle.com...[color=blue]
                    > The tweaks are:
                    >
                    > 1.
                    > These Interface(IOleC ommandTarget) were missing and it gave an error
                    > during Compilation, so I added this code:
                    > <code>
                    > <StructLayout(L ayoutKind.Seque ntial)> _
                    > Public 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)> _
                    > Public 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)> _
                    > Public Interface IOleCommandTarg et
                    > 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
                    > </code>
                    >
                    > 2. During the first time the Noborder or FlatScroll..... none of the
                    > setting were taking place only we load it again it got
                    > implemented...s o just triggered as follows:
                    > AxWebBrowser1.N avigate("about: blank")
                    > AxWebBrowser1.N avigate("http://www.google.com" )
                    >
                    > So this tweak allowed to achieve the desired effect on the Control
                    > during load itself......... ..
                    > It works pretty fine now......
                    > Regards
                    > Gokul Raja.D[/color]


                    Comment

                    • Charles Law

                      #11
                      Re: Using Web Browser Control in VB .net

                      [Copy of my e-mail reply to Gokul]

                      Hi Gokul

                      I will have a think about the first problem.

                      In the second, one thing that is notable is the changing of the designMode
                      state. Each time you change the state of this, you need to call SetUIHandler
                      to set the IDocHostUIHandl er again. It gets cleared when the designMode
                      state changes. You should also set up the handler for the
                      HTMLDocumentEve nts2 interface again (and any others that you use, on the
                      body for example).

                      I am also not convinced of the validity of using oSel.text <> "Control". Try
                      using AxWebBrowser1.d ocument.selecti on.type instead. I think you will find
                      it more reliable. It will return "None", "Text", or "Control", depending on
                      what is selected.

                      Let me know if these suggestions help, and if you still have problem 1 after
                      the changes.

                      I notice that you are using late binding. Generally, I would suggest using
                      Option Explicit On and Option Strict On. It can help pick up some unintended
                      typographic errors.

                      Regards

                      Charles


                      "gokul" <gokulrajad@yah oo.com> wrote in message
                      news:c1f374f7.0 308111122.20d11 87f@posting.goo gle.com...[color=blue]
                      > Hi Charles........ ........
                      > Things are pretty fine as far as the changing the interface features
                      > of the Web Browser.
                      >
                      > But the earlier working modules of mine have become error prone
                      > :(........the issues are
                      >
                      > 1. I have a search facility where in from a group of HTML pages I
                      > search and display the pages list which contain the phrase/ word, then
                      > I take to the page on a click........th is doesn't work now.......
                      > But I have (Previous and Next buttons ) in my form to navigate the
                      > pages....they work pretty fine......durin g my debugging process I
                      > came to find that the control is not in the form itself......
                      >
                      > I just tried a small example, once I click the search results, I will
                      > pass on the URL to a textbox.....tho ugh Iam able to retrieve the
                      > value using "textbox1.text" , Iam unable to see the changes on the
                      > form.........th at is Iam unable to view the text changes in my
                      > textbox.
                      >
                      > 2. Unable to access the DOM.
                      > Earlier I was able to access the document as follows:
                      >
                      > Dim doc As HTMLDocument
                      > doc = AxWebBrowser1.D ocument
                      > AxWebBrowser1.D ocument.designM ode = "on"
                      > doc.body.setAtt ribute("content Editable", "true")
                      > Dim oSel = doc.selection.c reateRange()
                      > Dim objSelTxt As Object
                      > objSelTxt = oSel.text
                      >
                      > objSelTxt = "<font style='backgrou nd-color: #FFFF99;'>" &
                      > objSelTxt & "</font>"
                      > If oSel.text <> "" And oSel.text <> "Control" Then
                      > oSel.pasteHtml( objSelTxt)
                      > End If
                      >
                      > doc.body.setAtt ribute("content Editable", "false")
                      > AxWebBrowser1.D ocument.designM ode = "off"
                      > =============== =============== =============== ========
                      > But now, it gives me an error:
                      > Object variable or With block variable not set.
                      >
                      > Hope u have come across these issues......... and awaiting your
                      > views....charle s.
                      > Thank You and Regards
                      > Gokul Raja.D[/color]


                      Comment

                      • gokul

                        #12
                        Re: Using Web Browser Control in VB .net

                        Dear Charles,
                        I did tried your suggestions and couldn't come up with the
                        solution.....

                        (thank you for the tip AxWebBrowser1.d ocument.selecti on.type )But
                        Iam unable to get the text that is selected on the Page without using
                        osel.text, now oSel.text also gives me problems....

                        and the second question is related to the First question I had
                        Yesterday for you........
                        I use a ShowDialog to display a list of URL's and from a list of
                        hyperlinks present in the dialog Iam suppose to navigate to the
                        corresponding pages in my Browser.

                        But Iam unable to achieve it.

                        Regards
                        Gokul

                        Comment

                        • gokul

                          #13
                          Re: Using Web Browser Control in VB .net

                          The Showdialog was the Culprit it wasn't allowing the change of
                          control to my other form and I had Issues....it is solved
                          now..........

                          But to get the selected text from the Browser control is my major
                          problem.

                          Regards
                          Gokul

                          Comment

                          • Charles Law

                            #14
                            Re: Using Web Browser Control in VB .net

                            Gokul

                            I use the following function, copied from the MSDN, to get at the current
                            selection. Does this do what you want?

                            Public Function GetElementUnder InsertionPoint( ByVal doc As
                            mshtml.IHTMLDoc ument2) As mshtml.IHTMLEle ment
                            '************** ************
                            ' Function copied from MSDN
                            '************** ************
                            Select Case doc.selection.t ype
                            Case "None", "Text"
                            ' This reduces the selection to just the insertion
                            ' point. The parentElement method will then return the
                            ' element directly under the mouse pointer.
                            Dim rg As mshtml.IHTMLTxt Range

                            rg = CType(AxWebBrow ser1.document.s election.create Range,
                            mshtml.IHTMLTxt Range)
                            rg.collapse()

                            Return rg.parentElemen t

                            Case "Control"
                            ' A form or image is selected. The commonParentEle ment
                            ' will return the site selected element.
                            Dim ctlRg As mshtml.IHTMLCon trolRange

                            ctlRg = CType(AxWebBrow ser1.document.s election.create Range,
                            mshtml.IHTMLCon trolRange)

                            Return ctlRg.commonPar entElement

                            Case Else
                            MsgBox("Unexpec ted type: " & doc.selection.t ype)

                            Return Nothing

                            End Select

                            End Function

                            HTH

                            Charles


                            "gokul" <gokulrajad@yah oo.com> wrote in message
                            news:c1f374f7.0 308120152.7ca2d cd@posting.goog le.com...[color=blue]
                            > The Showdialog was the Culprit it wasn't allowing the change of
                            > control to my other form and I had Issues....it is solved
                            > now..........
                            >
                            > But to get the selected text from the Browser control is my major
                            > problem.
                            >
                            > Regards
                            > Gokul[/color]


                            Comment

                            • gokul

                              #15
                              Re: Using Web Browser Control in VB .net

                              Dear Charles,
                              Thanks for the Tip, it worked....Indee d I posted a reply last night
                              .........but I couldn't figure why it hasn't posted here......

                              Thanks a lot.....
                              Regards
                              Gokul Raja.D

                              Comment

                              Working...