in reply to "Correct" icons in selfbuild "Explorer"

I'm not entirely clear what you are trying to do, and I don't mess with windows, but you might find zicons-Tk-Icon-Selector interesting.

Are you trying to extract the icons out of Explorer? You might run into them being "inlined" right into the binary or some resource dll. It's not really a Tk question.


I'm not really a human, but I play one on earth. Cogito ergo sum a bum
  • Comment on Re: "Correct" icons in selfbuild "Explorer"

Replies are listed 'Best First'.
Re^2: "Correct" icons in selfbuild "Explorer"
by Ace128 (Hermit) on Jul 30, 2006 at 20:47 UTC
    After some extra digging, it seems like Win32::Exe could be the answer as this seems to be able of extracting icons... However, its litte tricky since there seems to be several icons. Best would be to somehow access the registry and extract exactly which .ico is used from the associated .exe file! Tricky, but cool to solve in Perl :) Anyone here done it already maybe? ;)
        *Sign* I never manage to make the code I do with Win32::API work! So for I managed to do this:
        use Win32::API; use Data::Dumper; use strict; use warnings; # http://msdn.microsoft.com/library/default.asp?url=/library/en-us/she +llcc/platform/shell/reference/functions/shgetfileinfo.asp # DWORD_PTR SHGetFileInfo( # LPCTSTR pszPath, # DWORD dwFileAttributes, # SHFILEINFO *psfi, # UINT cbFileInfo, # UINT uFlags # ); # typedef struct _SHFILEINFO { # HICON hIcon; # int iIcon; # DWORD dwAttributes; # TCHAR szDisplayName[MAX_PATH]; # TCHAR szTypeName[80]; # } SHFILEINFO; sub FILE_ATTRIBUTE_NORMAL { 0x00000080 } sub SHGFI_ICONLOCATION { 4096 } sub DWORD_SIZE { 4 } my $shell32 = 'shell32.dll'; my $pszPath = 'test.exe'; #my $dwFileAttributes = FILE_ATTRIBUTE_NORMAL; my $dwFileAttributes = 0; # typedef struct _SHFILEINFO { # HICON hIcon; # int iIcon; # DWORD dwAttributes; # TCHAR szDisplayName[MAX_PATH]; # TCHAR szTypeName[80]; # } SHFILEINFO; # -- - - # Method #1 Win32::API::Struct->typedef( 'SHFILEINFO', qw( HICON hIcon; int iIcon; DWORD dwAttributes; TCHAR szDisplayName[255]; TCHAR szTypeName[80]; ) ); #my $fileinfo = Win32::API->Import($shell32, 'DWORD SHGetFileInfo( LP +CTSTR pszPath, DWORD dwFileAttributes, SHFILEINFO *psfi, UINT cbFileI +nfo, UINT uFlags)'); #my $SHFILEINFO = Win32::API::Struct->new( 'SHFILEINFO' ); #print Dumper($SHFILEINFO); #my $cbFileInfo = $SHFILEINFO->sizeof; # -- - - # Method #2 my $SHFILEINFO = pack("LiLCC"); my $cbFileInfo = length($SHFILEINFO); # ---- my $uFlags = SHGFI_ICONLOCATION; my $SHGetFileInfo = new Win32::API($shell32, 'SHGetFileInfo', 'PNPII', 'N') || die $^E; my $dword_p = $SHGetFileInfo->Call( $pszPath, $dwFileAttributes, $SHFILEINFO, $cbFileInfo, $uFlags, ) || die $^E; # For Method #1 #my $dword_p = SHGetFileInfo( # $pszPath, # $dwFileAttributes, # $SHFILEINFO, # $cbFileInfo, # $uFlags, #) || die $^E; #print "DD: " . $SHFILEINFO->{szDisplayName} . "\n"; # ------ print Dumper($SHFILEINFO);
        but with no luck! Could someone please make this work? I prefer making method #2 work, but I guess anything is ok at this point.

        I am folloing this:
        " SHGFI_ICONLOCATION
        Retrieve the name of the file that contains the icon representing the file specified by pszPath, as returned by the IExtractIcon::GetIconLocation method of the file's icon handler. Also retrieve the icon index within that file. The name of the file containing the icon is copied to the szDisplayName member of the structure specified by psfi. The icon's index is copied to that structure's iIcon member."

        And seems easy enough. But its quite tricky and complicated with all the arrays and structs here..

        Thanks big time,
        Ace