ZjiÜt∞nφ jmΘna a cesty defaultnφho prohlφ₧eΦe HTML

Postup:
Zalo₧te nov² projekt. Do deklaraΦnφ Φßsti formulß°e zapiÜte:

Option Explicit

Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String,  ByVal sResult As String) As Long
Private Declare Function GetTempPath Lib "kernel32"  Alias "GetTempPathA" (ByVal nSize As Long, ByVal lpBuffer As String) As Long

Private Const MAX_PATH = 260
Private Const ERROR_FILE_NO_ASSOCIATION = 31&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_FILE_SUCCESS = 32& 
Private Const ERROR_BAD_FORMAT = 11&

Private Function GetBrowserName(dwFlagReturned As Long) As String

   Dim hFile As Long
   Dim sResult As String
   Dim sTempFolder As String
        
  'doΦasn² adresß°
   sTempFolder = GetTempDir()
   
  'vytvo°enφ prßzdnΘho html  souboru v temp adresß°i
   hFile = FreeFile
      Open sTempFolder & "dummy.html" For Output As #hFile
   Close #hFile

  'zjiÜt∞nφ jmΘna a cesty souboru asociovanΘho s html
   sResult = Space$(MAX_PATH)
   dwFlagReturned = FindExecutable("dummy.html", sTempFolder, sResult)
  
  'odstran∞nφ doΦasnΘho html
   Kill sTempFolder & "dummy.html"
   
   GetBrowserName = TrimNull(sResult)
   
End Function


Private Function TrimNull(item As String)

    Dim pos As Integer
   
    pos = InStr(item, Chr$(0))
    
    If pos Then
          TrimNull = Left$(item, pos - 1)
    Else: TrimNull = item
    End If
  
End Function


Public Function GetTempDir() As String

    Dim nSize As Long
    Dim tmp As String
    
    tmp = Space$(256)
    nSize = Len(tmp)
    Call GetTempPath(nSize, tmp)
    
    GetTempDir = TrimNull(tmp)
    
End Function

Na formulß° p°idejte tlaΦφtko. Na udßlost click:

Private Sub Command1_Click()

   Dim success As Long
   Dim sBrowser As String
   
   sBrowser = GetBrowserName(success)
   
  'mo₧nΘ nßvratovΘ hodnoty
   Select Case success
      
     'volßnφ bylo ·sp∞ÜnΘ
      Case Is >= ERROR_FILE_SUCCESS
      
         MsgBox sBrowser
         Exit Sub
         
     'dalÜφ mo₧nΘ nßvratovΘ hodnoty
      Case ERROR_FILE_NO_ASSOCIATION
      Case ERROR_FILE_NOT_FOUND
      Case ERROR_PATH_NOT_FOUND
      Case ERROR_BAD_FORMAT
      Case Else:
   End Select
      
   
  'Pokud nebyl browser nalezen
   MsgBox "Nenalezeno!"
   
End Sub

Zp∞t

Autor: The Bozena