Extract all icons from an EXE without using ExtractIconEx

前端 未结 2 518
野的像风
野的像风 2020-12-17 02:34

I need to extract all icons from an EXE and save them as disk files, but I cannot use the simplest solution (ExtractIconEx) because I need to extract the ICO files in a way

相关标签:
2条回答
  • 2020-12-17 02:51

    Here is a working example on Delphi Praxis. It reads the default RT_GROUP_ICON and associated RT_ICON resources for a specified executable and saves them as as a complete multi-image .ICO file.

    It seems to be confused by 256 pixel images (saves with invalid format), at least on XP, so it might need a little tweaking.

    0 讨论(0)
  • 2020-12-17 02:52

    The PrivateExtractIcons function can help you. You can specify the size of the icon which you want to extract:

    {$IFDEF UNICODE}
        function PrivateExtractIcons(lpszFile: PChar; nIconIndex, cxIcon, cyIcon: integer; phicon: PHANDLE; piconid: PDWORD; nicon, flags: DWORD): DWORD; stdcall ; external 'user32.dll' name 'PrivateExtractIconsW';
    {$ELSE}
        function PrivateExtractIcons(lpszFile: PChar; nIconIndex, cxIcon, cyIcon: integer; phicon: PHANDLE; piconid: PDWORD; nicon, flags: DWORD): DWORD; stdcall ; external 'user32.dll' name 'PrivateExtractIconsA';
    {$ENDIF}
    
    procedure TMainForm.Button1Click(Sender: TObject);
    var
        hIcon   : THandle;
        nIconId : DWORD;
        Icon    : TIcon;
    begin
        //Extract a 128x128 icon
        if PrivateExtractIcons ('C:\Users\Public\Documents\RAD Studio\Projects\2010\Aero Colorizer\AeroColorizer.exe', 0, 128, 128, @hIcon, @nIconId, 1, LR_LOADFROMFILE) <>0 then
        try
            Icon:=TIcon.Create;
            try
                Icon.Handle:=hIcon;
                Icon.SaveToFile(ExtractFilePath(ParamStr(0))+'Aicon.ico');
            finally
                Icon.Free;
            end;
        finally
            DestroyIcon (hIcon);
        end;
    end ;
    
    0 讨论(0)
提交回复
热议问题