Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing URL to user's default browser

0 views
Skip to first unread message

Frank Culp

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

I would like to use an image control's click event to open the user's
default browser and open a preset URL. In essence, my app will have my
logo at the bottom and when clicked, my URL would pull up the default
browser and my web site.

I have looked endlessly for this, but have had no luck. Any help would
be appreciated.

Frank
-------------
fr...@franksplace.com

Ben Baird (MSMVP)

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

I have a code sample for this -- Article #00001 in the KnowledgeBase section
on my homepage.
--
Ben Baird, MVP
Microsoft SiteBuilder Network Level 2
Visual Basic Thunder, version 2.0
http://www.cyberhighway.com/~psy/
Common Controls Replacement Project, Official Member
http://www.zeode-sd.com/ccrp/
Please direct your programming questions to the newsgroups.

Frank Culp wrote in message <34FAADD1...@franksplace.com>...

Walther Musch

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

On Mon, 02 Mar 1998 07:02:09 -0600, Frank Culp <fr...@franksplace.com>
wrote:

>I would like to use an image control's click event to open the user's
>default browser and open a preset URL. In essence, my app will have my
>logo at the bottom and when clicked, my URL would pull up the default

Check out http://pi1438.kub.nl:2080/VisualBasicSource/

for the file (example) URl (different versions & solutions!!)


gr. walther


http://pi1438.kub.nl:2080/Frankrijk/

Massimo Luciani

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Use the following routines:

Function currentBrowser$()
Dim hKey As Long

Dim strPathsKey As String
searchstring = "SOFTWARE\Classes\http\shell\open\command"

Dim strResolved As String
strResolved = Space$(255)
'XX& = RegOpenKey(HKEY_LOCAL_MACHINE, searchstring, hKey)
If Not RegOpenKey(HKEY_LOCAL_MACHINE, searchstring, hKey) Then
RegQueryValue HKEY_LOCAL_MACHINE, searchstring, strResolved, 255
RegCloseKey hKey
Temp$ = strResolved
End If
'MsgBox (temp)
For x% = 1 To Len(Temp$)
This$ = Mid(Temp$, x, 3)
If UCase(This$) = "EXE" Then
For y = x To Len(Temp$)
If Mid(Temp$, y, 1) = " " Then
currentBrowser = Left(Temp$, y)
Exit Function
End If
Next y
currentBrowser = Temp$ ' No space was found so return whole
string
Exit Function
End If
Next x
End Function

This one finds the default browser.

Sub StartBrowser(URL As String)

'This code will start the current browser which
'should be Netscape.

'THIS CODE WILL NOT WORK WITH INTERNET EXPLORER!
'If Netscape is not started, this code will start
'it and pass it the URL to open

On Error GoTo HolyCowPattiesBatman

'Set linkmode to none
frmTreeview.DDEThing.LinkMode = 0

'This is the DDE topic we will use
frmTreeview.DDEThing.LinkTopic = Browser$ & "|WWW_OpenURL"

'The following line is what we are going to say
'to netscape. The DWORD value 0xFFFFFFFF is what
'tells netscape to use the existing window. Change
'to 0x0 to make it start spawning new windows.
frmTreeview.DDEThing.LinkItem = URL & ",,0xFFFFFFFF,0x0"

'Set to manual
frmTreeview.DDEThing.LinkMode = 2
'Do it
frmTreeview.imlRagni.Tag = "2"
frmTreeview.DDEThing.LinkRequest

frmTreeview.DDEThing.LinkMode = 0

'This is the activate topic
'frmTreeview.DDEThing.LinkTopic = Browser$ & "|WWW_Activate"

'Bring the last active netscape
'window to the front, otherwise it
'stays in the back behind your application
'frmTreeview.DDEThing.LinkItem = "0xFFFFFFFF,0x0"

'frmTreeview.DDEThing.LinkMode = 2
'frmTreeview.DDEThing.LinkRequest

Exit Sub

HolyCowPattiesBatman:

If Err = 282 Then
'No DDE response, we can assume netscape is not running

'This will shell Netscape and pass the URL as an argument
Shell (BroPath$ & " " & URL), 1
Exit Sub
End If

End Sub

Keep in mind that BroPath$=currentbrowser while Browser$ is the name of
the browser without the path, with only the exe name (generally "iexplore"
or "netscape").

--
Ciao :-)
Massimo

Nell'indirizzo, sostituire lana con seta
In the address, replace lana with seta

Frank Culp <fr...@franksplace.com> wrote in article
<34FAADD1...@franksplace.com>...


> I would like to use an image control's click event to open the user's
> default browser and open a preset URL. In essence, my app will have my
> logo at the bottom and when clicked, my URL would pull up the default

> browser and my web site.
>

Wolfgang John

unread,
Mar 6, 1998, 3:00:00 AM3/6/98
to

"Massimo Luciani" <mluc...@mail.lana.it> wrote:

>
>Frank Culp <fr...@franksplace.com> wrote in article
><34FAADD1...@franksplace.com>...
>> I would like to use an image control's click event to open the user's
>> default browser and open a preset URL. In essence, my app will have my
>> logo at the bottom and when clicked, my URL would pull up the default
>> browser and my web site.
>>
>> I have looked endlessly for this, but have had no luck. Any help would
>> be appreciated.
>>
>> Frank
>> -------------
>> fr...@franksplace.com
>>

I use the ShellExecute function:

n = ShellExecute(Me.hWnd, "open", urlString$, "", "", 1)

n = ShellExecute(Me.hWnd, "Open", "mailto:" & emailAddr$, "", "", 1)

The above takes advantage of the File Types declarations in the
Explorer.

It works great with most systems, however, it appears it does not work
on virgin systems with Netscape 4 that never had any MS browser
installed.

I imagine that is part of the MS vs Netscape war. I am hoping MS will
come up with a "cure" for that.


--
Wolfgang John - AM-WOLJO Shareware -
wj...@fix.net http://www.fix.net/~wjohn/
- Phone Dialer and Logger - CD Player and Library - Win3.x / Win95 / NT
- CD Player imports data from GIANT internet library -
- FREE programmable 6 cities/countries world clock -

Please remove "nospam" from my signature if replying by email.

Rick Palmer

unread,
Mar 10, 1998, 3:00:00 AM3/10/98
to

Frank,

Check out the shellexecute api, which is simple to use and doesn't require
digging around in the registry for the default browser. Pass the routine
your URL and let Windows do the rest.

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

GoToWebSite "http://www.prosoftapps.com"

Public Sub GoToWebSite(URL As String)

Dim www As Long
'Open URL with default browser

On Error Resume Next
www = ShellExecute(frmMain.hwnd, "Open", URL, "", App.Path,
SW_SHOWNORMAL)

If Err Then
Msg = MsgBox("Could not open your default web browser." & _
vbCrLf & "Please make sure it is correctly installed.",
vbCritical)
End If

End Sub

--
Rick Palmer
________________________
Software Developer/Publisher, ProSoft Apps ri...@prosoftapps.com
http://www.prosoftapps.com
Hydraulic Engineer, Corps of Engineers rick.a...@usace.army.mil
http://www.europa.com/~psapps

Wolfgang John

unread,
Mar 12, 1998, 3:00:00 AM3/12/98
to

"Rick Palmer" <rick.a...@usace.army.mil> wrote:

>Frank,
>
>Check out the shellexecute api, which is simple to use and doesn't require
>digging around in the registry for the default browser. Pass the routine
>your URL and let Windows do the rest.
>
>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
>
>GoToWebSite "http://www.prosoftapps.com"
>
>Public Sub GoToWebSite(URL As String)
>
> Dim www As Long
> 'Open URL with default browser
>
> On Error Resume Next
> www = ShellExecute(frmMain.hwnd, "Open", URL, "", App.Path,
>SW_SHOWNORMAL)
>
> If Err Then
> Msg = MsgBox("Could not open your default web browser." & _
> vbCrLf & "Please make sure it is correctly installed.",
>vbCritical)
> End If
>
>End Sub
>
>--
>Rick Palmer

I have found that people with "virgin" systems and only Netscape 4
can't use the above method. Apparently Netscape 4 and above no longer
registers the program properly.

0 new messages