I am developing a zip file application using the SourceForge zip component.
I need add the icon associated with the file stored in the zip file and get the index of the associated icon to add the icon to a TListview that contains the zip file information.
The filename in the zip file does not exist on the disk only in the zip file.
When I run the SysImageList demo that gets the system image index and displays the associated icon the index (6) and the icon is the same for these for 'bogusfile.pas", 'bogusfile.dpr"and 'bogusfile.dfm".
I do not understand system image lists very well; however, when I load the SysImageList icons into a list box it only contains 6 icons.
if I build my own system image list I get 620 icons but I have to call FileIconInit to get all the system icons.
Is the SysImageList component supposed to hold all the system's icons or only a few of the icons?
- Code: Select all
// Reinitializes the system image list.
// Set FullInit to TRUE to restore the system image cache from disk; FALSE otherwise.
function FileIconInit( FullInit: BOOL ): BOOL; stdcall;
type
TFileIconInit = function( FullInit: BOOL ): BOOL; stdcall;
var
ShellDLL: HMODULE;
PFileIconInit: TFileIconInit;
begin
Result := False;
if ( Win32Platform = VER_PLATFORM_WIN32_NT ) then
begin
ShellDLL := GetModuleHandle( PChar( Shell32 ) );
PFileIconInit := GetProcAddress( ShellDLL, PChar( 660 ) );
if ( Assigned( PFileIconInit ) ) then
Result := PFileIconInit( FullInit );
end;
end;
function GetSystemSmallIconsList: TCustomImageList;
// This gets the system image list.
var
SysIL: HImageList;
SFI: TSHFileInfo;
MyImages: TCustomImageList;
begin
// This gets the small image list
SysIL := SHGetFileInfo( '', 0, SFI, SizeOf( SFI ), SHGFI_SYSICONINDEX or SHGFI_SMALLICON );
if SysIL <> 0 then
begin
MyImages := TCustomImageList.Create( nil );
// Assign the system list to the component
MyImages.Handle := SysIL;
// The following prevents the image list handle from being
// destroyed when the component is.
MyImages.ShareImages := TRUE;
Result := MyImages;
end;
end;
function GetSystemLargeIconsList: TCustomImageList;
// This gets the system image list.
var
SysIL: HImageList;
SFI: TSHFileInfo;
MyImages: TCustomImageList;
begin
// This gets the large image list.
SysIL := SHGetFileInfo( '', 0, SFI, SizeOf( SFI ), SHGFI_SYSICONINDEX or SHGFI_LARGEICON );
if SysIL <> 0 then
begin
MyImages := TCustomImageList.Create( nil );
// Assign the system list to the component
MyImages.Handle := SysIL;
// The following prevents the image list handle from being
// destroyed when the component is.
MyImages.ShareImages := TRUE;
Result := MyImages;
end;
end;
// Return the SystemIconIndex baised on the FileExtension
// Return the SystemIconIndex baised on the FileExtension
// If the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag,
// this parameter does not have to be a valid file name.
// The function will proceed as if the file exists with the specified name and with
// the file attributes passed in the dwFileAttributes parameter.
// This allows you to obtain information about a file type by passing just the extension
// for pszPath and passing FILE_ATTRIBUTE_NORMAL in dwFileAttributes.
function GetIconIndex( FileExtension: string ): integer;
var
SFI: TSHFileInfo;
begin
Result := -1;
ZeroMemory( @SFI, SizeOf( SFI ) );
[b] SHGetFileInfo( PChar( 'bogusfile' + FileExtension ), FILE_ATTRIBUTE_NORMAL or SHGFI_SYSICONINDEX, SFI, SizeOf( SFI ), [/b]SHGFI_USEFILEATTRIBUTES );
Result := SFI.iIcon;
end;
procedure TForm1.FormCreate( Sender: TObject );
begin
[b] FileIconInit( true );[/b]
SystemImageList := GetSystemSmallIconsList;
ListView1.SmallImages := SystemImageList;
end;
procedure TForm1.FormDestroy( Sender: TObject );
begin
SystemImageList.Free;
end;
procedure TForm1.FormShow( Sender: TObject );
var
i: integer;
ListItem: TListItem;
begin
dxImageListBox1.ImageList := SystemImageList;
for i := 0 to SystemImageList.Count - 1 do
begin
dxImageListBox1.Items.Add( IntToStr( i ) );
dxImageListBox1.ImageIndexes[ i ] := i;
end;
end;
If I set the IconSet property to isSystem then double click the SysImageList component in the Delphi 2009 ide I get an exception - "Failed to write ImageList data to stream".
If I change the IconSize property to isSmallIcons from isLargeIcons the height and width property does not change from 32x32 to 16x16.
I can not get the associated icon for some file types with the SysImageList component.
I can not get the associated icon index with my own function GetIconIndex( FileExtension: string ): integer; with my own systemimagelist. Get GetIconIndex always returns 0 for SFI.iIcon.
The approach you used to get the iconindex is to create a temporary file when the filename does not exist. The documentation for SHGetFileInfo says that If the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag, this parameter does not have to be a valid file name. You do not use this parameter when calling SHGetFileInfo.
I am stuck. Neither the SysImageList component or my own code is working.
Any assistance to fix SysImageList component or my own code would be apprecated.
Regards,
Bill