我不知道它的大小.
我现在使用此代码来检索图标的句柄并将其与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;
是的,它只是代码的一部分(如果你想我会全部显示).
它仅适用于一个问题:CreateIconfromResource函数给我任何以32×32拉伸的图标:
1 http://22.imagebam.com/download/u7q9PTEAUlSeZ1IJXQ5ViA/15321/153201662/bad.PNG
但我希望以原始分辨率获取图标:
2 http://56.imagebam.com/download/yH_Nc9dfsADso0W9A2bL1w/15321/153204932/good.PNG
我知道CreateIconfromResource旨在以相同的分辨率获得它们,这就是我正在寻找另一个功能的原因.
谢谢您的帮助.
解决方法
CreateIconFromResourceEx允许您提供所需的宽度/高度,而CreateIconFromResource使用默认的系统mertics(如针对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.