Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > opening a html page


Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2004, 04:17 AM
irisbenji irisbenji is offline
Freshman
 
Join Date: Sep 2003
Location: France
Posts: 40
Default opening a html page


Hello

I have a path c:/
In c: there is directly a MyPage.html

I want this page to be opened (displayed) during the execution of my program.
Whats the code that will open it? (shell seems to work only with bat or exe files...am I wrong?)

thanks a lot
Reply With Quote
  #2  
Old 01-05-2004, 04:22 AM
_Arno_'s Avatar
_Arno_ _Arno_ is offline
Junior Contributor
 
Join Date: Sep 2003
Location: netherlands, n'gein
Posts: 209
Default

get the webbrowser control ( press ctrl+t )
this way it opens on the form.
if u want it to open in explorer use the shell() function
__________________
New Design! : Get your own messagebar!
Reply With Quote
  #3  
Old 01-05-2004, 04:33 AM
spamonkey8's Avatar
spamonkey8 spamonkey8 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: Between Your Ears
Posts: 337
Default

We get so many posts on this, I'll explain all methods I know here. There are many ways to do this, and they will all work with files as well. Some will open the URL within the form, some will open it with the default browser.

The ShellExecute API will open any file or url with its associated application. For more info, go to APIList's Page.

Code:
Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" (ByVal hwnd As Long, _ ByVal lpOperation As String, ByVal lpFile As _ String, ByVal lpParameters As String, ByVal _ lpDirectory As String, ByVal nShowCmd As Long) As Long ShellExecute Me.hwnd, vbNullString, "http://www.google.com", _ vbNullString, "C:\", SW_SHOWNORMAL

You can also shell through explorer.exe to open the default browser:
Code:
Shell "explorer.exe http://www.google.com"

Or through a browser directly, such as Internet Explorer (iexplore.exe) or my favorite, Avant Browser (avant.exe):
Code:
Shell "C:\Program Files\Internet Explorer\iexplore.exe http://www.google.com" Shell "C:\Program Files\Avant Browser\avant.exe http://www.google.com"

And even another method, using rundll32.exe to use url.dll to open the browser:
Code:
Shell "rundll32.exe url.dll,FileProtocolHandler http://www.google.com"

To use the webbrowser control, press Control - T and select "Microsoft Internet Controls". Add it to the form and open a page like this:
Code:
WebBrowser1.Navigate "http://www.google.com"

If you'd like to specify what HTML code goes into the frame, load the page "about:blank" whenever convenient and set this event:
Code:
Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant) WebBrowser1.Document.Body.InnerHTML = "<H1>This is the content</H1>" End Sub

You can press Control - T and add the "Microsoft Internet Transfer Controls". This will open any URL into a string for writing to a disk or display as you like:
Code:
Dim strData as String strData = Inet1.OpenURL("http://www.google.com")
__________________
[vb] and [/vb] tags make the world go 'round

Last edited by spamonkey8; 01-05-2004 at 04:47 AM.
Reply With Quote
  #4  
Old 01-05-2004, 03:00 PM
wooliewillie wooliewillie is offline
Newcomer
 
Join Date: Jan 2004
Posts: 3
Default

Give a man a fish and he eats for a day, teach a man to fish and he eats for a lifetime. Where is the documentation for Microsoft Internet Controls? Does it exist?
Reply With Quote
  #5  
Old 01-05-2004, 03:06 PM
HiTmAN's Avatar
HiTmAN HiTmAN is offline
Contributor
 
Join Date: Mar 2003
Location: The FSB
Posts: 570
Default

Look on MSDN.
__________________
MSDN is your friend.

3L Designs
Reply With Quote
  #6  
Old 01-05-2004, 03:07 PM
McFly2003 McFly2003 is offline
Newcomer
 
Join Date: Oct 2003
Posts: 12
Default

Or you could use the Shell function :

result = Shell("C:\Program Files\Internet Explorer\Iexplore.exe " & AppPath & "\myhtml.html, vbMaximizedFocus)
Reply With Quote
  #7  
Old 01-05-2004, 03:08 PM
HiTmAN's Avatar
HiTmAN HiTmAN is offline
Contributor
 
Join Date: Mar 2003
Location: The FSB
Posts: 570
Default

Using the Shell function might be a problem, because the path to IE might be different.

I would recommend using the ShellExecute method, as the API requires only Windows 95 and upwards, and it does not require you hard-code any paths.

As a bonus, it opens in the default browser (I think), in case someone is using Mozilla or Opera (or another) rather than IE.
__________________
MSDN is your friend.

3L Designs
Reply With Quote
  #8  
Old 01-05-2004, 03:11 PM
McFly2003 McFly2003 is offline
Newcomer
 
Join Date: Oct 2003
Posts: 12
Default

Quote:
Originally Posted by HiTmAN
Using the Shell function might be a problem, because the path to IE might be different.

I would recommend using the ShellExecute method, as the API requires only Windows 95 and upwards, and it does not require you hard-code any paths.

As a bonus, it opens in the default browser (I think), in case someone is using Mozilla or Opera (or another) rather than IE.



You are right, I took a shortcut here. If you want to use ShellExecute, you'll have to declare it in a module or something, unlike Shell
Reply With Quote
  #9  
Old 01-05-2004, 03:12 PM
HiTmAN's Avatar
HiTmAN HiTmAN is offline
Contributor
 
Join Date: Mar 2003
Location: The FSB
Posts: 570
Default

True, but this shouldn't be too much of an inconvinience.

Anyway, back on topic, this isn't a debate about which method to use, that is the choice of the person who is asking the question.
__________________
MSDN is your friend.

3L Designs
Reply With Quote
  #10  
Old 01-05-2004, 05:51 PM
idew idew is offline
Newcomer
 
Join Date: Dec 2003
Location: Texas
Posts: 17
Default

Necessity is the mother of invention - Debates lead to a greater good for those that read in need!
Reply With Quote
  #11  
Old 01-06-2004, 01:49 AM
spamonkey8's Avatar
spamonkey8 spamonkey8 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: Between Your Ears
Posts: 337
Default

McFly2003, I refer you to my 3rd method

The path to iexplore is a pretty constant thing, but I, myself, would prefer shelling through explorer or rundll32.
__________________
[vb] and [/vb] tags make the world go 'round
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
disable print preview from xlDialogPrint w_seyller Excel 9 12-11-2003 11:20 AM
how stop displaying an html page ? ali_purashuri Web Programming 0 09-18-2003 05:31 AM
how to edit a html page itself? fandecine General 10 08-21-2003 12:47 AM
HTML / CSS within a VB script manchego Web Programming 3 06-24-2003 12:28 PM
Send Email with graphics and text Greatchap Communications 2 05-16-2003 06:44 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->