all groups > dotnet general > july 2003 >
You're in the

dotnet general

group:

Using Web Browser Control in VB .net


Using Web Browser Control in VB .net gokulrajad NO[at]SPAM yahoo.com
7/31/2003 11:21:13 PM
dotnet general:
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
Re: Using Web Browser Control in VB .net Charles Law
8/1/2003 8:51:15 AM
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


[quoted text, click to view]

Re: Using Web Browser Control in VB .net Gokul RajaD
8/3/2003 9:57:28 AM
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....fine 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 MyCustomWebBrowser

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



*** Sent via Developersdex http://www.developersdex.com ***
Re: Using Web Browser Control in VB .net Charles Law
8/3/2003 7:05:20 PM
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.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER)

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

Regards

Charles


[quoted text, click to view]

Re: Using Web Browser Control in VB .net gokulrajad NO[at]SPAM yahoo.com
8/6/2003 8:35:54 AM
Dear Charles Law,
I need to remove the 3D border of the Webbrowser control, they say it
could be achieved using IDocHostUIHandler.

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
Re: Using Web Browser Control in VB .net Charles Law
8/6/2003 11:41:30 PM
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_DIALOG = &H1
DOCHOSTUIFLAG_DISABLE_HELP_MENU = &H2
DOCHOSTUIFLAG_NO3DBORDER = &H4
DOCHOSTUIFLAG_SCROLL_NO = &H8
DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = &H10
DOCHOSTUIFLAG_OPENNEWWIN = &H20
DOCHOSTUIFLAG_DISABLE_OFFSCREEN = &H40
DOCHOSTUIFLAG_FLAT_SCROLLBAR = &H80
DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = &H100
DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = &H200
DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY = &H400
DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = &H800
DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = &H1000
DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = &H2000
DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = &H4000
DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION = &H10000
DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION = &H20000
DOCHOSTUIFLAG_THEME = &H40000
DOCHOSTUIFLAG_NOTHEME = &H80000
DOCHOSTUIFLAG_NOPICS = &H100000
DOCHOSTUIFLAG_NO3DOUTERBORDER = &H200000
End Enum

Public Enum DOCHOSTUIDBLCLK
DOCHOSTUIDBLCLK_DEFAULT = 0
DOCHOSTUIDBLCLK_SHOWPROPERTIES = 1
DOCHOSTUIDBLCLK_SHOWCODE = 2
End Enum

' MSG structure
<StructLayout(LayoutKind.Sequential)> _
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(LayoutKind.Sequential)> _
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

' OLEMENUGROUPWIDTHS structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure OLEMENUGROUPWIDTHS
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=6)> _
Dim width() As Integer
End Structure

' ICustomDoc interface
<ComVisible(True), ComImport(),
Guid("3050f3f0-98b5-11cf-bb82-00aa00bdce0b"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface ICustomDoc
Sub SetUIHandler(ByVal pUIHandler As IDocHostUIHandler)
End Interface

' IOleWindow interface
<ComVisible(True), ComImport(),
Guid("00000114-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleWindow
Sub GetWindow(ByVal phwnd As IntPtr)
Sub ContextSensitiveHelp(ByVal fEnterMode As Boolean)
End Interface

' IOleInPlaceActiveObject interface
<ComVisible(True), ComImport(),
Guid("00000117-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleInPlaceActiveObject : Inherits IOleWindow
' IOleWindow interface
Shadows Sub GetWindow(ByVal phwnd As IntPtr)
Shadows Sub ContextSensitiveHelp(ByVal fEnterMode As Boolean)
Sub TranslateAccelerator(ByRef lpmsg As MSG)
Sub OnFrameWindowActivate(ByVal fActivate As Boolean)
Sub OnDocWindowActivate(ByVal fActivate As Boolean)
Sub ResizeBorder(ByRef prcBorder As tagRECT, ByVal pUIWindow As
IOleInPlaceUIWindow, ByVal fFrameWindow As Boolean)
Sub EnableModeless(ByVal fEnable As Boolean)
End Interface

' IOleInPlaceUIWindow interface
<ComVisible(True), ComImport(),
Guid("00000115-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleInPlaceUIWindow : Inherits IOleWindow
' IOleWindow interface
Shadows Sub GetWindow(ByVal phwnd As IntPtr)
Shadows Sub ContextSensitiveHelp(ByVal fEnterMode As Boolean)
Sub GetBorder(ByRef lprectBorder As tagRECT)
Sub RequestBorderSpace(ByRef pborderwidths As tagRECT)
Sub SetBorderSpace(ByRef pborderwidths As tagRECT)
Sub SetActiveObject(ByVal pActiveObject As IOleInPlaceActiveObject,
ByVal pszObjName As String)
End Interface

' IDropTarget interface
<ComVisible(True), ComImport(),
Guid("00000122-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
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

' IOleInPlaceFrame interface
<ComVisible(True), ComImport(),
Guid("00000116-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleInPlaceFrame : Inherits IOleInPlaceUIWindow
' IOleWindow interface
Shadows Sub GetWindow(ByVal phwnd As IntPtr)
Shadows Sub ContextSensitiveHelp(ByVal fEnterMode As Boolean)

' IOleInPlaceUIWindow interface
Shadows Sub GetBorder(ByRef lprectBorder As tagRECT)
Shadows Sub RequestBorderSpace(ByRef pborderwidths As tagRECT)
Shadows Sub SetBorderSpace(ByRef pborderwidths As tagRECT)
Shadows Sub SetActiveObject(ByVal pActiveObject As
IOleInPlaceActiveObject, ByVal pszObjName As String)

' TODO: hmenuShared should be a reference to a remotable handle
Sub InsertMenus(ByVal hmenuShared As IntPtr, ByRef lpMenuWidths As
OLEMENUGROUPWIDTHS)
Sub SetMenu(ByVal hmenuShared As IntPtr, ByVal holemenu As IntPtr, ByVal
hwndActiveObject As IntPtr)
Sub RemoveMenus(ByVal hmenuShared As IntPtr)
Sub SetStatusText(ByVal pszStatusText As String)
Sub EnableModeless(ByVal fEnable As Boolean)
Sub TranslateAccelerator(ByRef lpmsg As MSG, ByVal wID As UInt16)
End Interface

' IDocHostUIHandler interface
<ComVisible(True), ComImport(),
Guid("bd3f23c0-d43e-11cf-893b-00aa00bdce1a"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IDocHostUIHandler

<PreserveSig()> _
Function ShowContextMenu( _
ByVal dwID As Integer, _
ByRef ppt As tagPOINT, _
<MarshalAs(UnmanagedType.IUnknown)> ByVal pcmdtReserved As Object, _
<MarshalAs(UnmanagedType.IDispatch)> ByVal pdispReserved As Object)
As Integer

Sub GetHostInfo(ByRef pInfo As DOCHOSTUIINFO)

<PreserveSig()> _
Function ShowUI( _
ByVal dwID As Integer, _
ByVal pActiveObject As IOleInPlaceActiveObject, _
ByVal pCommandTarget As IOleCommandTarget, _
ByVal pFrame As IOleInPlaceFrame, _
ByVal pDoc As IOleInPlaceUIWindow) As Integer

Sub HideUI()
Sub UpdateUI()
Sub EnableModeless(ByVal fEnable As Boolean)
Sub OnDocWindowActivate(ByVal fActivate As Boolean)
Sub OnFrameWindowActivate(ByVal fActivate As Boolean)

Re: Using Web Browser Control in VB .net gokulrajad NO[at]SPAM yahoo.com
8/7/2003 9:53:35 AM
Hi Charles,

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

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

Thank You

Regards
Re: Using Web Browser Control in VB .net gokulrajad NO[at]SPAM yahoo.com
8/7/2003 9:48:18 PM
The tweaks are:

1.
These Interface(IOleCommandTarget) were missing and it gave an error
during Compilation, so I added this code:
<code>
<StructLayout(LayoutKind.Sequential)> _
Public Structure OLECMDTEXT
Public cmdtextf As UInt32
Public cwActual As UInt32
Public cwBuf As UInt32
Public rgwz As Char
End Structure

<StructLayout(LayoutKind.Sequential)> _
Public 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)> _
Public Interface IOleCommandTarget
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
</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...so just triggered as follows:
AxWebBrowser1.Navigate("about:blank")
AxWebBrowser1.Navigate("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
Re: Using Web Browser Control in VB .net Charles Law
8/8/2003 9:34:47 AM
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 IOLECommandTarget interface in future. In particular, the 'longs'
translate to integers in .NET.

<code>
' OLECMD
<StructLayout(LayoutKind.Sequential)> _
Public Structure OLECMD
Public cmdID As Int32
Public cmdf As Int32
End Structure

' OLECMDTEXT
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.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(UnmanagedType.ByValTStr, SizeConst:=256)> _
Public text As String
End Class

' IOleCommandTarget interface
<ComImport(), Guid("b722bccb-4e68-101b-a2bc-00aa00404770"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IOleCommandTarget

Sub QueryStatus(ByRef pguidCmdGroup As Guid, ByVal cCmds As Int32, _
<InAttribute(), Out(), MarshalAs(UnmanagedType.LPArray,
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.ReadyState =
SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
Application.DoEvents()
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


[quoted text, click to view]

AddThis Social Bookmark Button