472,378 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

Using AxWebBrowser in VB 2005

Doe
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 found some code on MSDN forums, but the extention didn't really cover
RegisterAsBrowser. 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
RegisterAsBrowser. (Yes, someone on this group told me the browsers are
basically the same just "wrapped" differently.)

Dim ThisBrowser as New SHDocVw.AxWebBrowser

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.SHDocVw 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

Mar 16 '06 #1
7 6700
> 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
Mar 16 '06 #2
CMM
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

Mar 17 '06 #3
Doe
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 RegisterAsBrowser. 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

Mar 17 '06 #4
CMM
You should have looked more closely. From within the inherited "extended"
WebBrowser class I posted...

Me.UnderlyingBrowser.RegisterAsBrowser = True

The code for "UnderlyingBrowser" is simply:

Public ReadOnly Property UnderlyingBrowser() As SHDocVw.WebBrowser

Get
Return CType(Me.ActiveXInstance, SHDocVw.WebBrowser)
End Get

End Property
--
-C. Moya
www.cmoya.com
"Doe" <do*******@aol.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
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 RegisterAsBrowser. 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

Mar 17 '06 #5
Doe
Cool.

Doe

Mar 17 '06 #6
CMM
Clarification to previous post (read it first):
Actually I made UnderlyingBrowser private to the class... you can easily
make it public and expose it or make a new wrapper property for
RegisterAsBrowser as so:

Public Property RegisterAsBrowser() As Boolean
Get
Return Me.UnderlyingBrowser.RegisterAsBrowser
End Get
Set(ByVal value As Boolean)
Me.UnderlyingBrowser.RegisterAsBrowser = value
End Set
End Property
--
-C. Moya
www.cmoya.com
"CMM" <cm*@nospam.com> wrote in message
news:OF**************@TK2MSFTNGP09.phx.gbl...
You should have looked more closely. From within the inherited "extended"
WebBrowser class I posted...

Me.UnderlyingBrowser.RegisterAsBrowser = True

The code for "UnderlyingBrowser" is simply:

Public ReadOnly Property UnderlyingBrowser() As SHDocVw.WebBrowser

Get
Return CType(Me.ActiveXInstance, SHDocVw.WebBrowser)
End Get

End Property
--
-C. Moya
www.cmoya.com
"Doe" <do*******@aol.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
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 RegisterAsBrowser. 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


Mar 17 '06 #7
Doe
Okay, there is something I am not understanding here. I finally got
around to testing this. When I try it, calling RegisterAsBrowser, I get
an error message -- must use new keyword.

I am doing:
Dim ThisBrowser As EnhancedWebBrowser

ThisBrowser = New EnhancedWebBrowser
ThisBrowser.UnderlyingBrowser.RegisterAsBrowser = 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

Mar 27 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: antoine Veret | last post by:
Hi, is there changes on axWebBrowser with framework 1.1 ? events doesn't fire for this object. and an other question; how release memory for axWebBrowser object ? when i create those objects,...
0
by: Matthias Kwiedor | last post by:
I have a aplication which hosts an axWebbrowser. This activex component needs about 10 to 15 mb of memory. Because i have a option to move the aplication to tray icon and do some timer work i...
1
by: Les Caudle | last post by:
I created an app that uses an axWebBrowser control to display a local xml file and had no problems. When the form is initially loaded, it displays an htm file that says no file is loaded: ...
0
by: beau | last post by:
Hi, I'm using the AxWebBrowser in a C# WinForms application. I've got the basics working, but need some help controlling the view options for browsing files. How can I disable the...
0
by: sagar.jawale | last post by:
Hi, In my c# windows application, i am using AxSHDocVw.AxWebBrowser. I am displaying a generated receipt html in this browser. Also, for printing the same html, i am using the following command...
6
by: Dave Booker | last post by:
It appears that I cannot correctly install the AxWebBrowser in VS2005. I can instantiate an "AxWebBrowser browser" and refer to its members, properties, and methods. I'm having trouble with the...
4
by: =?Utf-8?B?RGF2ZSBF?= | last post by:
I have written an application that reads third party web pages. If I am using HTTP everything works fine. I create an AxSHDocVw.AxWebBrowser object and then Navigate2 to the page. I then...
2
by: Michael | last post by:
Hi experts, I am using axWebBrowser in windows form to load web pages. There is a page that contains a group of buttons. (More than 10 buttons.) The source code behind each button is like below:...
1
by: tim2006 | last post by:
When i try to run the program, it just hangs. If i remove the axwebbrowser control it works fine. Any ideas? Here is my code: class1.vb Imports System.Windows.Forms Imports...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.