Extract the icon from the file and place it in Timage. The icon can be obtained both from the exe file and associated with the file type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Uses Winapi.ShellAPI; ... var filePath : WideString; icoSize: Integer; begin filePath:= 'C:\Windows\regedit.exe'; icoSize:= SHGFI_SMALLICON; Img1.Picture.Icon.Handle:= getShellFileIcon(filePath, icoSize); filePath:= 'C:\Windows\System32\termsrv.dll'; icoSize:= SHGFI_LARGEICON; Img2.Picture.Icon.Handle:= getShellFileIcon(filePath, icoSize); end; |
Options
filePath - path to the file
icoSize - icon size
- SHGFI_SMALLICON - 16x16
- SHGFI_LARGEICON - 32x32
Result
A handle to the icon, or 0 on failure.
1 2 3 4 5 6 7 8 9 10 11 |
function getShellFileIcon(filePath: WideString; icoSize: integer): HICON; var shfi: TShFileInfo; begin try FillChar(shfi, SizeOf(TShFileInfo), 0); ShGetFileInfo(PChar(filePath), 0, shfi, SizeOf(TShFileInfo), SHGFI_ICON or icoSize); Result:= shfi.hIcon; except Result:= 0; end; end; |