Registriert seit: 13. Okt 2010
Ort: Bayern
490 Beiträge
Delphi 10.4 Sydney
|
AW: TComboboxEx - Icons sind schwarz
28. Jul 2012, 06:02
Mit dem Unterschied/Vorbehalt, daß es bei mir um Icons ging:
Delphi-Quellcode:
procedure AddIconToImageList(
const AFileName : string
; var AAddToImageList : TImageList
);
var
licnIcon : TIcon;
lsfiFileInfo: SHFILEINFO;
limgInter : TImage;
lsExePath : string;
begin
// Create a temporary TIcon
licnIcon := TIcon.Create;
limgInter := TImage.Create(nil);
try
//Get The Icon That Represents The File
FillChar(lsfiFileInfo, SizeOf(lsfiFileInfo), 0);
SHGetFileInfo(PChar(AFileName + #0), 0, lsfiFileInfo, SizeOf(lsfiFileInfo), SHGFI_ICON {or SHGFI_LARGEICON});
licnIcon.Transparent := True;
licnIcon.Handle := lsfiFileInfo.hIcon;
// add the icon to the imagelist:
if Assigned(AAddToImageList) then
begin
limgInter.Width := licnIcon.Width;
limgInter.Height := licnIcon.Height;
limgInter.Picture.Bitmap.Width := licnIcon.Width;
limgInter.Picture.Bitmap.Height := licnIcon.Height;
limgInter.Canvas.FillRect(Rect(0, 0, limgInter.Picture.Bitmap.Width, limgInter.Picture.Bitmap.Height));
limgInter.Transparent := True;
limgInter.Picture.Bitmap.TransparentColor := clWhite;
if DrawIcon(limgInter.Canvas.Handle, 0, 0, licnIcon.Handle) then
begin
//
end
else
begin
licnIcon.ReleaseHandle;
licnIcon.Handle := GetIconHandleOfExtension(ExtractFileExt(AFileName), lsExePath);
DrawIcon(limgInter.Canvas.Handle, 0, 0, licnIcon.Handle);
end;
AAddToImageList.AddMasked(limgInter.Picture.Bitmap, limgInter.Picture.Bitmap.TransparentColor);
end;
DestroyIcon(lsfiFileInfo.hIcon);
finally
FreeAndNil(licnIcon);
FreeAndNil(limgInter);
end;
end;
HTH
Nr.1 Delphi-Tool: [F7]
|
|
Zitat
|