 |
 |

01-05-2004, 04:17 AM
|
|
Freshman
|
|
Join Date: Sep 2003
Location: France
Posts: 40
|
|
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
|
|

01-05-2004, 04:22 AM
|
 |
Junior Contributor
|
|
Join Date: Sep 2003
Location: netherlands, n'gein
Posts: 209
|
|
|
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
|
|

01-05-2004, 04:33 AM
|
 |
Junior Contributor
|
|
Join Date: Apr 2003
Location: Between Your Ears
Posts: 337
|
|
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.
|

01-05-2004, 03:00 PM
|
|
Newcomer
|
|
Join Date: Jan 2004
Posts: 3
|
|
|
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?
|
|

01-05-2004, 03:06 PM
|
 |
Contributor
|
|
Join Date: Mar 2003
Location: The FSB
Posts: 570
|
|
|

01-05-2004, 03:07 PM
|
|
Newcomer
|
|
Join Date: Oct 2003
Posts: 12
|
|
|
Or you could use the Shell function :
result = Shell("C:\Program Files\Internet Explorer\Iexplore.exe " & AppPath & "\myhtml.html, vbMaximizedFocus)
|
|

01-05-2004, 03:08 PM
|
 |
Contributor
|
|
Join Date: Mar 2003
Location: The FSB
Posts: 570
|
|
|
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.
|
|

01-05-2004, 03:11 PM
|
|
Newcomer
|
|
Join Date: Oct 2003
Posts: 12
|
|
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
|
|

01-05-2004, 03:12 PM
|
 |
Contributor
|
|
Join Date: Mar 2003
Location: The FSB
Posts: 570
|
|
|
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.
|
|

01-05-2004, 05:51 PM
|
|
Newcomer
|
|
Join Date: Dec 2003
Location: Texas
Posts: 17
|
|
|
Necessity is the mother of invention - Debates lead to a greater good for those that read in need!
|
|

01-06-2004, 01:49 AM
|
 |
Junior Contributor
|
|
Join Date: Apr 2003
Location: Between Your Ears
Posts: 337
|
|
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
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|