Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Launch default browser (all-terrain)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Launch default browser (all-terrain)

    this code should launch the default browser to a specified website under virtually all circumstances
    if it doesnt work for you, please let me know in http://www.powerbasic.com/support/pb...ead.php?t=4112

    Code:
    #compile exe
    #include "win32api.inc"
      
    function getdefaultbrowser() as string
    on error resume next
      local hkey as long, keytype as long
      local szbuffer as asciiz * %max_path, szregpath as asciiz * %max_path
      szregpath  = "htmlfile\shell\open\command"
      if regopenkeyex(%hkey_classes_root, szregpath, 0&, %key_query_value, hkey) <> %error_success then
         goto searchfiles
         exit function
      end if
      if regqueryvalueex(hkey, ", 0&, keytype, szbuffer, %max_path) <> %error_success then
         goto searchfiles
         exit function
      end if
      regclosekey hkey
      function = szbuffer
      exit function
     searchfiles:  'registry lookup failed, search directly for known browsers
      if dir$("c:\progra~1\intern~1\iexplore.exe",39) <> " then
        function = "c:\progra~1\intern~1\iexplore.exe"
        exit function
      end if
      if dir$("c:\progra~1\mi332f~1\iexplore.exe",39) <> " then
        function = "c:\progra~1\mi332f~1\iexplore.exe"
        exit function
      end if
      if dir$("c:\progra~1\plus!\micros~1\iexplore.exe ",39) <> " then
        function = "c:\progra~1\plus!\micros~1\iexplore.exe "
        exit function
      end if
      if dir$("c:\progra~1\plus!\micros~2\iexplore.exe ",39) <> " then
        function = "c:\progra~1\plus!\micros~2\iexplore.exe "
        exit function
      end if
     function = "
    end function
       
    sub launchdefaultbrowser(surl as string)
    on error resume next
      dim ret as long, mybrowser as string
      mybrowser = getdefaultbrowser
      if mybrowser = " then goto launchshellexecute
      ret = shell(mybrowser & " " & surl, %sw_shownormal)
      if ret <> 0 then exit sub
      launchshellexecute:
      ret = shellexecute(byval %null, "open", surl + chr$(0), byval %null, byval %null, %sw_shownormal)
      if ret = 2 or ret = 0 then
         msgbox "strewth! it failed, even after all that hard work"
      end if
    end sub
      
    function pbmain() as long
     launchdefaultbrowser "http://www.powerbasic.com"
    end function

    [this message has been edited by wayne diamond (edited july 22, 2001).]
    -
Working...
X