Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

IconHandle von Icon Datei

  Alt 25. Apr 2019, 21:17
Meine Funktion..

Delphi-Quellcode:
function TSkinPopUpMenu.GetHIconFromFile(AFileName: PWideChar; ASmall: Boolean; AIndex: Integer)
  : HIcon;
var
  LDummy: HIcon;
  LInfo: TSHFileInfo;
begin
  Result := 0;

  If ExtractIconEx(AFileName, -1, Result, LDummy, 0) <> 0 then
  begin
    If ASmall then
      ExtractIconEx(AFileName, AIndex, LDummy, Result, 1)
    else
      ExtractIconEx(AFileName, AIndex, Result, LDummy, 1);
  end
  else
  begin
    SHGetFileInfo(PWideChar(ExtractFileExt(AFileName)), FILE_ATTRIBUTE_NORMAL, LInfo,
      SizeOf(LInfo), IfThen(ASmall, SHGFI_SMALLICON, SHGFI_LARGEICON)
      or SHGFI_ICON or SHGFI_LINKOVERLAY or SHGFI_USEFILEATTRIBUTES);
    Result := LInfo.HIcon;
  end;
end;
Aufruf..
Delphi-Quellcode:
  if ImageIconPath <> 'then
  begin
    FIcon[ButtonCount].ImageIcon := GetHIconFromFile(ImageIconPath, true);
    if (FIcon[ButtonCount].ImageIcon <> 0) then
      btnMenu[ButtonCount].ImageDrop(HButton, FIcon[ButtonCount], X, Y, W, H);
  end;
Freigeben..
Delphi-Quellcode:
  if ButtonCount > 0 then
  begin
    for IntI := 0 to ButtonCount - 1 do
    begin
      btnMenu[IntI].ImageDropRemove(btnMenu[IntI].Handle);
      btnMenu[IntI].DestroyWindow;
      btnMenu[IntI] := nil;
    end;
    SetLength(btnMenu, 0);
    SetLength(FIcon, 0);
    ButtonCount := 0;
  end;
Funktioniert soweit alles..
Aber!

Wenn ich das PopuMenu ca.. 30 > 40 mal hintereinander aufrufe dann schlägt das fehl.
If ExtractIconEx(AFileName, -1, Result, LDummy, 0) <> 0 then

und kracht dann in
Result := LInfo.HIcon;

Warum? Wenn doch alle Icon Handles freigegeben werden.
Delphi-Quellcode:
procedure TSkinPushButton.ImageDropRemove(WinHandle: HWND);
begin

  if ImgDrop <> 0 then
  begin
    DestroyIcon(ImgDrop);
    SkinEngine.SetImageProperty(WinHandle, PROP_IMAGE_DROP, 0);
  end;
end;
gruss

Geändert von EWeiss (25. Apr 2019 um 21:20 Uhr)
  Mit Zitat antworten Zitat