Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

opening internet explorer 1

Status
Not open for further replies.

itechC

Programmer
Feb 13, 2003
71
0
0
CA
I need to open internet explorer with a given url in my application. Any ideas. Thanks
 

External to your program? If so then look up the shell function or either of the API's of ShellExecute or ShellExecuteEx. Inside your program? If so then use the webbrowser control and the navigate method.

Good Luck

 
Yes its external my application. I'll try the shell command. Thanks
 
Put these two lines in the declaration section of a form or in a module

Const SW_NORMAL = 1

Private 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
____________________________________________________________________________

Put a label on a form and make the caption look like a hyperlink. Something like - " and make it light blue(maybe underline it).

Next put this code in the labels click event.

ShellExecute frmAbout.hwnd, "open", label1.Caption, "", "", SW_NORMAL

The ShellExecute will open up the users default browser and go to the web address passed to it.

You simply pass ShellExecute 6 things:
1. The form hwnd - In my case the frmAbout.hwnd

2. The operation to be done - in my case the "open" command

3. The file name - In my case the label caption, or pass it a string with the web address.

4. Any Parameters - In my case I had none so put empty string

5. The directory - In my case had none so put empty string

6. How to show the window when it opens - In my case I choose normal (can be hidden, or minimize also).

Good Luck
 
I am also trying to open up a web browser outside of my application. I already had these few lines that Darmo talkes about, but I am having problems with Windows98 machines. This works great on Windows XP, but on my Windows98 machine, nothing happens. It does not execute the ShellExecute line.

Any thoughts?
 
the simplest methd is to use shell function like this.

Shell "explorer ", vbNormalFocus for example,... unfurl="true"]http://www.tek-tips.com", vbNormalFocus

Thats it.
 
It is not necessary to shell it. You can set a reference to an internet explorer library which holds the IWebBrowser2 interface. You can then execute internet explorer, navigate to the page you want and do whatever you want. It's really very simple, however I forgot the name of the library to reference. I did this just a few days ago, when I get back home I'll post you the code and the reference.
Greetings,
Rick
 
Ok, here it is:


On Error GoTo ErrHandler

Dim objBrowser As InternetExplorer

Set objBrowser = New InternetExplorer
objBrowser.Visible = True

objBrowser.Navigate "
Set objBrowser = Nothing

On Error GoTo 0
Exit Sub



The library referenced is called 'Microsoft Internet Controls' (in binary shdocvw.dll).

Greetings,
Rick
 
Well, first of all, since we're targetting windows here, we can safely assume internet explorer at least is on the system. And second; I believe the original question was "I need to open internet explorer with a given url in my application. Any ideas. Thanks"....

And last, but certainly not least; apart from the URL to surf to, ShellExecute doesn't give you much control over the instance being launched, whereas an interface pointer to the instance gives you much control (almost full control I would say)
Greetings,
Rick
 
Easiest way is to Shell rundll32.exe to invoke the http protocol handler. This will use whatever browser is registered as the default.

Eg, I always put a link to my web site (label containing caption: on Help - About forms. This code run from the label click, opens the URL in the browser:

Private Sub lblURL_Click()

On Error GoTo ErrTrap

Dim lngRtn As Long

Unload Me
lngRtn = Shell("rundll32.exe url.dll,FileProtocolHandler & lblURL.Caption)

GoTo ExitSub

ErrTrap:
MsgBox "Error " & Format$(Err.Number, "#0") & " - message: " & _
Err.Description & "." & vbCrLf & "Raised by object: " & Err.Source & ".", _
vbCritical + vbOKOnly, "System Error"
Resume ExitSub

ExitSub:

End Sub

Paul Bent
Northwind IT Systems
 
Hey, LazyMe, my comment was to the orginal poster, not you. Many people think that IE is the only web browser there is. An end-user will become frustrated if they have to open a web page with something other than their default browser (I know I would if a program continually opened Netscape for me to view a web page). ShellExecute will open the default browser and I believe using the windows API for such a small operation like this is <b>A LOT</b> better than creating new objects. Be an idiot:
 
vicky21 or anyone else that may know...
do you know of a link to a page that discusses all the API's that need the MSLU for Win 95/98/ME

thanks for your help!
 
Vicky,

I'm a little concerned about your assertion that ShellExecute does not work on some 98 and Win Me machines, and that this is documented in MSDN. Can you provide a reference, as this is news to me.

The line that you quote concerning Microsoft Layer for Unicode merely means that there is a Wide version of the ShellExecute API (ShellExecuteW) which, if you want to use it instead of the ANSI version (ShellExecuteA) in W9x/Me, requires the MLUC (it should also be pointed out that this advice is mostly directed to C/C++ programmers, as it is rather difficult to jump through the necessary hoops to leverage unicoWS.dll in VB)

 
I am well aware of the MSDN documentation. There is nothing there to suggest the ShellExec does not work under W9x/Me. Hence my question
 
Sorry strongm, I didn't mean to offend you, I've read a lot of your posts and know you know your stuff. I am aware that the ShellExecute API is supported in Win 95/Win NT 3.1 and up. I was wondering why dcdogxx was not able to make the statement suceed in Win98. I have seen many different values used for the lpParameters and lpDirectory parameters (eg: vbNullString,NULL,0,&quot;&quot;) and was wondering if there is a value that works on all OS's (or if any of them do not).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top