微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

delphi – 可以从Vista Shell获取48×48或64×64图标?

如果Vista Shell中存在48×48或64×64图标,您可以使用SHGetFileInfo如何获取timage显示的句柄?

我想从一个代表文件夹路径的图像列表中选择一个图标,并在timage显示一个48×48或64×64的图标。

// load the large system image for the current path into Image1
SHGetFileInfo( PChar( CurrentPath ),FILE_ATTRIBUTE_norMAL,SFI,SizeOf( TSHFileInfo ),SHGFI_ICON or SHGFI_LARGEICON or SHGFI_SHELLICONSIZE or
             SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_disPLAYNAME );
aimageIndex := SFI.iIcon;
ImageList2.GetBitmap( aimageIndex,Image1.Picture.Bitmap );

法案

解决方法

您必须使用 SHGetImageList功能,以获得具有较大图标的图像列表。

这里有一个例子在delphi中

uses ShellApi,Commctrl,ShlObj;

const
  SHIL_LARGE     = $00;  //The image size is normally 32x32 pixels. However,if the Use large icons option is selected from the Effects section of the Appearance tab in display Properties,the image is 48x48 pixels.
  SHIL_SMALL     = $01;  //These images are the Shell standard small icon size of 16x16,but the size can be customized by the user.
  SHIL_EXTRALARGE= $02;  //These images are the Shell standard extra-large icon size. This is typically 48x48,but the size can be customized by the user.
  SHIL_SYSSMALL  = $03;  //These images are the size specified by GetSystemMetrics called with SM_CXSMICON and GetSystemMetrics called with SM_CYSMICON.
  SHIL_JUMBO     = $04;  //Windows Vista and later. The image is normally 256x256 pixels.
  IID_IImageList: TGUID= '{46EB5926-582E-4017-9FDF-E8998DAA0950}';

function GetimageListSH(SHIL_FLAG:Cardinal): HIMAGELIST;
type
  _SHGetimageList = function (iImageList: integer; const riid: TGUID; var ppv: Pointer): hResult; stdcall;
var
  Handle        : THandle;
  SHGetimageList: _SHGetimageList;
begin
  Result:= 0;
  Handle:= LoadLibrary('Shell32.dll');
  if Handle<> S_OK then
  try
    SHGetimageList:= GetProcAddress(Handle,PChar(727));
    if Assigned(SHGetimageList) and (Win32Platform = VER_PLATFORM_WIN32_NT) then
      SHGetimageList(SHIL_FLAG,IID_IImageList,Pointer(Result));
  finally
    FreeLibrary(Handle);
  end;
end;


Procedure GetIconFromFile(aFile:String; var aIcon : TIcon;SHIL_FLAG:Cardinal);
var
  aimgList    : HIMAGELIST;
  SFI         : TSHFileInfo;
Begin
    //Get the index of the imagelist
    SHGetFileInfo(PChar(aFile),SHGFI_ICON or SHGFI_LARGEICON or SHGFI_SHELLICONSIZE or
                 SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_disPLAYNAME );

    if not Assigned(aIcon) then
    aIcon:= TIcon.Create;
    //get the imagelist
    aimgList:= GetimageListSH(SHIL_FLAG);
    //extract the icon handle
    aIcon.Handle:= ImageList_GetIcon(aimgList,Pred(ImageList_GetimageCount(aimgList)),ILD_norMAL);
End;

你可以这样使用这些功能

var
 hicon :TIcon;
begin
    hicon:= TIcon.Create;
    try
     GetIconFromFile('C:\Tools\reflector\readme.htm',hicon,SHIL_JUMBO);
     Image1.Picture.Icon.Assign(hIcon); //assign to timage
    finally
     hIcon.Free;
    end;
end;

原文地址:https://www.jb51.cc/delphi/103373.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐