Hello,
I use Lazarus 1.8.4 in Windows 10 Pro German.
I coded a small procedure that can extract the icon from an application and stores the icon on the hard drive.
The name and the full path of the application are in an edit field (edtFileName).
Unfortunately all icons on the hard drive have a black background although they are shown with a transparent background in the Lazarus form.
Here is my code:
procedure TfrmMainForm.btnSaveClick(Sender: TObject);
var
IconHandle: THandle;
ExtractedIcon: Ticon;
IconDatei: Array[0..255] of char;
IconSaveFile: String;
begin
// Create an Icon
ExtractedIcon := Ticon.create;
// Copy the name + path of the EXE to an Array of Char
StrPcopy(IconDatei,edtFileName.Text);
// Extract the icon and show it in the Image control
IconHandle := ExtractIcon(hInstance, IconDatei, 0);
ExtractedIcon.Handle := IconHandle;
imgIcon.Picture.Icon := ExtractedIcon;
// File Name of the Icon file is the current folder + File-name of the EXE (where the icon is extractedfrom)
IconSaveFile := ExtractFilePath(Paramstr(0));
IconSaveFile := IconSaveFile + ExtractFileName(edtFileName.Text);
IconSaveFile := StringReplace(IconSaveFile, '.exe', '.ico', [rfReplaceAll, rfIgnoreCase]);
IconSaveFile := StringReplace(IconSaveFile, '.dll', '.ico', [rfReplaceAll, rfIgnoreCase]);
ExtractedIcon.SaveToFile(IconSaveFile);
ExtractedIcon.Free;
end;
I also tried to save the icon from the TImage control but this has the same effect:
imgIcon.Picture.Icon.SaveToFile(IconSaveFile');
Any idea where the problem might be?
Thank you!
Regards
OLLI