使用LoadImage兼容加载小型OEM图标 [英] Compliant loading of small OEM icon with LoadImage

查看:125
本文介绍了使用LoadImage兼容加载小型OEM图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我的代码符合 LoadImage 规范,但是尽管有明确指定的尺寸,但是加载的图像是最大的非PNG图标。

I believe what my code complies to LoadImage specification, but despite of explicitly specified dimensions, loaded image is largest non-PNG icon.

procedure TForm1.FormCreate(Sender: TObject);
begin
  Image1.Picture.Icon.Handle := LoadImage(
    0,
    MakeIntResource(OIC_SHIELD),
    IMAGE_ICON,
    GetSystemMetrics(SM_CXSMICON),
    GetSystemMetrics(SM_CYSMICON),
    LR_SHARED
  );
  Win32Check(Image1.Picture.Icon.HandleAllocated);

  OutputDebugString(PChar(Format('%d×%d', [
    Image1.Picture.Icon.Width, 
    Image1.Picture.Icon.Height
  ]))); //  128×128
end;

注意:我更喜欢兼容更新的 LoadImage 语义,而不是像 LoadIcon 语义) stackoverflow.com/questions/4285890/how-to-load-a-small-system-icon>这个问题

Note: i prefer to be compliant to newer LoadImage semantics rather than to rely on the explicit module and resource id (essentially falling back to LoadIcon semantics) as specified in the answer to this question.

LoadImage 规格的行情正好概述了我的互斥LoadImage行为(失败或使用先前加载的库存资源,忽略了所需的尺寸)的问题-请参阅< a href = https://stackoverflow.com/questions/6613513#6614015> Adrian McCarthy的答案。

Quotes from LoadImage specs are exactly outlining my problem with mutually exclusive LoadImage behaviours (either fail or use previously loaded stock resource, ignoring desired dimensions) - see Adrian McCarthy's answer.

OIC_SHIELD 是Windows 6.0或更高版本,但自4.0版开始,Windows中出现的其他股票图标(OIC_xxx常量)也是如此。

While OIC_SHIELD is Windows 6.0+ specific, the same happens with other stock icons (OIC_xxx constants) present in Windows since version 4.0.

推荐答案

在Vista及更高版本上使用 SHGetStockIconInfo ,解决方案f对于所有其他操作系统,请问另一个问题。

Use SHGetStockIconInfo on Vista and up, and the solution from the other question for all other operating systems.

这篇关于使用LoadImage兼容加载小型OEM图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆