FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Need sample that display default browser as an icon on butto
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Need sample that display default browser as an icon on butto
Posted: Tue Jun 06, 2017 04:35 AM

Hi guys,

I would like to have a button called "Open..." with an icon of whatever current default web browser is on it too.

Anyone has any code snippet to do this?

TIA

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Need sample that display default browser as an icon on butto
Posted: Thu Jun 08, 2017 03:10 AM
Instead of reading the web browser's icon from the exe itself I took the approach of preparing in advance the icons of commonly used browser and select which one to use after determining what is current default browser.

Anyone knows what is the tried and tested method to include alpha blended images in an rc compiled with brc? Is changing the resource compiler the only way to go?

Code (fw): Select all Collapse
function WebBrowserIcon()
  // code based on <!-- m --><a class="postlink" href="https://stackoverflow.com/questions/13621467/how-to-find-default-web-browser-using-c">https://stackoverflow.com/questions/136 ... er-using-c</a><!-- m -->

  local oReg, cProgId, cPath := "", nPos, cBrowser := "Unknown browser", cCom, cIcon := ""
    // determine prog id of default browser
    oReg := TReg32():New(HKEY_CURRENT_USER, "Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice" )
    cProgId := oReg:Get("ProgId")
    oReg:Close()
    do case
       case cProgId == "IE.HTTP"
            cBrowser := "Internet Explorer"
            cIcon := "ie.bmp"
       case cProgId == "FirefoxURL"
            cBrowser := "Firefox"
            cIcon := "firefox.bmp"
       case cProgId == "ChromeHTML"
            cBrowser := "Chrome"
            cIcon := "chrome.bmp"
       case cProgId == "OperaStable"
            cBrowser := "Opera"
            cIcon := "opera.bmp"
       case cProgId == "SafariHTML"
            cBrowser := "Safari"
       case cProgId == "AppXq0fevzme2pys62n3e0fbqa7peapykr8v"
            cBrowser := "Microsoft Edge"
            cIcon := "edge.bmp"
    endcase
    if !empty(cIcon)
       cIcon := ud_bmpDir() + "\" +cIcon
    endif

    // use the progid to determine path to exe
    if !empty(cProgId)
       oReg := TReg32():New(HKEY_CLASSES_ROOT, cProgId + "\shell\open\command" )
       cPath := oReg:Get()
       oReg:Close()
       if (nPos := at(".exe", cPath)) > 0
          cPath := left(cPath, nPos+5)
       endif
    endif
    if !empty(cPath)
       *cCom := 'iconsext.exe /save '+cPath+' "'+ud_bmpDir()+'" -icons'
       *waitrun(cCom, SW_HIDE)
    endif
return cIcon
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion