Delphi Imagelist: loading icons with ResourceLoad from .res

I am trying to load an icon from a res file into a list of images. I created a res file using Delphi ImageEditor.

And so I try to load the icon:

  //if ImageList1.ResourceLoad(rtIcon, 'TEXT_BOLD', clWhite) then
  if imagelist1.GetResource(rtIcon, 'TEXT_BOLD', 0, [lrDefaultColor], clRed) then
    showmessage('loaded')
  else
    showmessage('not loaded');

Both methods do not work. Any ideas? Thank!

+3
source share
2 answers

Methods ResourceLoadand GetResourceload the entire list of images from one specified image resource. The goal is for you to have one bitmap containing all the images intended to enter the list. The control then divides it into separate tiles based on the specified width and height of the list of images.

, . . . ( .) . ImageList_LoadImage .

, . , , . , LoadImage, . TIcon , , :

myicon := TIcon.Create;
try
  myicon.LoadFromResourceName(HInstance, 'TEXT_BOLD');
  FImageList.AddIcon(myicon);
finally
  myicon.Free;
end;
+4

windows :

...
var 
  myicon : Ticon;
  Hd: THandle;
begin

  Hd := LoadImage(HInstance, 'TEXT_BOLD', IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
  myicon := TIcon.Create;
  myicon.ReleaseHandle;
  myicon.Handle := Hd;
  FImageList.AddIcon(myicon);

end;
...
+1

Source: https://habr.com/ru/post/1750362/


All Articles