English 中文(简体)
如何从另一个使用Delphi的档案资源中装载一只icon?
原标题:How to load a single icon from the resources of another file using Delphi?

I want to load an icon (from another file) which doesn t have multiple icons embedded in it (it s not an icon group). I don t know its size. I use now this code to retrieve the handle of the icon and use it with a TIcon.Handle:

function ResourceToIconHandle(hFile: hModule; IDname: PChar): HICON;
var
   hGicon1,
   hLoadIcon1: THandle;
   pGIcon1: Pointer;
begin
   hGicon1 := FindResource(hFile, IDName, RT_ICON);
   if hGicon1 <> 0 then
   begin
      hLoadIcon1 := LoadResource(hFile, hGicon1);
      pGicon1 := LockResource(hLoadIcon1);
      Result := CreateIconfromResource(pGicon1,
           SizeofResource(hFile, hGicon1),
           True,
           $00030000);
   end;
end;

Yes, it s only a part of the code (if you want I ll show all). It works with only one problem: CreateIconfromResource function is giving me any icon streched at 32x32:

1”/

But I want to get the icons at their original resolution: 2

I know that CreateIconfromResource is designed to get them at the same resolution, that s why I m looking for another function. Thank you for your help.

最佳回答

使用<代码>CreateIconFromResourceEx代替CreateIconFromResource

<代码>CreateIconFromResourceEx,请您提供所希望的宽度/公顷, 创建IconFromResource 正在对这些系统使用默认系统(例如:上的解释>LR_DEFAULTSIZE):

Uses the width or height specified by the system metric values for cursors or icons, if the cxDesired or cyDesired values are set to zero. If this flag is not specified and cxDesired and cyDesired are set to zero, the function uses the actual resource size. If the resource contains multiple images, the function uses the size of the first image.

问题回答

Roman R.可能是正确的,但我也补充说,你必须确定TIcon客体的适当尺寸,然后才能确定手脚。





相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...