borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2013 Andrea Tincani
:: How to load the default mail client or the default browser and go to a specified page!

Author  

Andrea Tincani and David Costelloe

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
API Declarations

Option Explicit

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
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile _
    As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long

Public Enum T_WindowStyle
    Maximized = 3
    Normal = 1
    ShowOnly = 5
End Enum

Module

Public Sub GoToInternet(Parent As Form, URL As String, WindowStyle As T_WindowStyle)
    Dim lngReturn As Long

    If fsGetBrowserInfo Then
        lngReturn = ShellExecute(Parent.hwnd, "Open", URL, "", "", WindowStyle)
        If lngReturn <= 32 Then
' Error
            MsgBox "Web Page not Opened", vbExclamation, "URL Failed"
        End If
    Else
       
'* nope no Browser
        MsgBox "Could not find associated Browser", vbExclamation, "Browser Not Found"
    End If
End Sub

Public Function fsGetBrowserInfo() As Boolean
    Dim strFileName As String, strDummy As String
    Dim strBrowserExec As String * 255
    Dim lngRetVal As Long
    Dim intFileNumber As Integer

   
' Create a HTML file
    strBrowserExec = Space(255)
    strFileName = "C:\TEST.HTM"
    intFileNumber = FreeFile
    Open strFileName For Output As #intFileNumber
    Write #intFileNumber, "<HTML> <\HTML>"
    Close #intFileNumber
   
' Do we have an associated application?
    lngRetVal = FindExecutable(strFileName, strDummy, strBrowserExec)
    MsgBox "Found Browser: " & strBrowserExec
    strBrowserExec = Trim(strBrowserExec)
   
' If an application is found return True
    If lngRetVal <= 32 Or strBrowserExec="" Then
' Error
        fsGetBrowserInfo = False
    Else
        fsGetBrowserInfo = True
    End If
    Kill strFileName
End Function

Usage
'......................................................................................................................
'Insert two buttons into a form and try them, the first will open the default browser at the specified location, the second will open the default mail client and set the address to the specified send mail address

Option Explicit

Private Sub Command1_Click()
    GoToInternet Me, "http://www.welford-costelloe.com", Normal
End Sub

Private Sub Command2_Click()
    GoToInternet Me, "mailto:dwc99@home.com?SUBJECT=Hello This is cool", Normal
End Sub
:: Navigation

Home

NetAPI, Winsock and Internet

Previous Tip

Next Tip

:: Search this site
Google
:: Related Topics
icon 15-05-2013 Re: Data Type Mismatch - What does it mean..?? by estatistics
icon 11-02-2009 Re: Placing images and text on a crystal report by Aeric
icon 06-10-2006 Right Click Save As... using IE by Maverick
icon 24-04-2006 Re: Web Browser control by qwertypunk
icon 10-07-2005 Re: Getting system MACID by Goran
:: Sponsored Links



borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2013 Andrea Tincaniborder