Saturday, November 13, 2010

Delphi: Get system icon handle

Delphi function to retrieve the icon handle of a system resource. 


uses ShlObj;
 
function GetSystemIcon: HICON; 
var 
  FileInfo: TSHFileInfo;
  PIDL: PItemIDList;
begin
  SHGetSpecialFolderLocation(Application.Handle, CSIDL_DRIVES, PIDL);
  if SHGetFileInfo(PChar(PIDL), 0, FileInfo, SizeOf(TSHFileInfo),
     SHGFI_PIDL or SHGFI_SYSICONINDEX ) <> 0 then
        Result := FileInfo.iIcon;
end;
 
Constants defined in ShlObj.pas

  CSIDL_DESKTOP                       = $0000; // 
CSIDL_INTERNET                      = $0001; //Internet Explorer (icon on desktop)
  CSIDL_PROGRAMS                      = $0002; //Start Menu\Programs
  CSIDL_CONTROLS                      = $0003; //My Computer\Control Panel
  CSIDL_PRINTERS                      = $0004; //My Computer\Printers
  CSIDL_PERSONAL                      = $0005; //My Documents
  CSIDL_FAVORITES                     = $0006; //user\Favorites
  CSIDL_STARTUP                       = $0007; //Start Menu\Programs\Startup
  CSIDL_RECENT                        = $0008; //user\Recent
  CSIDL_SENDTO                        = $0009; //user\SendTo
  CSIDL_BITBUCKET                     = $000a; //user\Recycle Bin
  CSIDL_STARTMENU                     = $000b; //user\Start Menu
  CSIDL_DESKTOPDIRECTORY              = $0010; //user\Desktop
  CSIDL_DRIVES                        = $0011; //"My Computer" folder
  CSIDL_NETWORK                       = $0012; //Network Neighborhood (My Network Places)
  CSIDL_NETHOOD                       = $0013; //user\nethood
  CSIDL_FONTS                         = $0014; //windows\fonts
  CSIDL_TEMPLATES                     = $0015; //Templates folder
  CSIDL_COMMON_STARTMENU              = $0016; //All Users\Start Menu
  CSIDL_COMMON_PROGRAMS               = $0017; //All Users\Start Menu\Programs
  CSIDL_COMMON_STARTUP                = $0018; //All Users\Startup
  CSIDL_COMMON_DESKTOPDIRECTORY       = $0019; //All Users\Desktop
  CSIDL_APPDATA                       = $001A; //user\Application Data
  CSIDL_PRINTHOOD                     = $001B; //user\PrintHood

Wednesday, November 3, 2010

System.Data.Sqlite locks database, even on single threaded access

Sometimes while using the System.Data.Sqlite .Net library I noticed that when db access was finished with and the method doing the access had returned, there were still open file handles to the database file. Every subsequent access created a new perpetual file handle. I have found a way that fixes this, that works for me anyway ;-) ...