如何加载系统小图标?

发布于 2024-10-04 09:24:58 字数 313 浏览 0 评论 0原文

我需要显示 16x16 像素的错误/警告/信息图标。不幸的是,LoadIcon(0, IDI_*)LoadImage(0, OIC_*, IMAGE_ICON, 16, 16, LR_SHARED) 总是给我 32x32 版本的图标。

我读到了有关 ShGetStockIconInfo 的内容,但这仅适用于 Vista 及以上版本,而且我仍然需要支持 XP。

有什么想法吗?

如果重要的话,我正在使用带有 TImage 组件的 Delphi 2010。

I need to display 16x16 pixel icons for error/warning/information. Unfortunately both LoadIcon(0, IDI_*) and LoadImage(0, OIC_*, IMAGE_ICON, 16, 16, LR_SHARED) always give me the 32x32 version of the icon.

I read about ShGetStockIconInfo but that is only available from Vista onwards and I still need to support XP.

Any ideas?

I'm using Delphi 2010 with a TImage component if that matters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流绪微梦 2024-10-11 09:24:58

问题是,当您这样做时,您会获得图标的缓存版本,即系统加载的第一个图标。这将是大尺寸的图标,通常为 32x32。您指定的尺寸并不重要。

您可以做的是在 user32.dll 中找到所需资源的 ID 并使用类似以下内容:

LoadImage(GetModuleHandle('user32'), MAKEINTRESOURCE(103), IMAGE_ICON,
    16, 16, LR_DEFAULTCOLOR);

您最好调用 GetSystemMetrics(SM_CXSMICON) 来获取图标大小,而不是硬调用代码 16,但您可能已经知道了。

我不确定您从哪里获取 user32 中资源的资源 ID,或者即使它们能保证它们在不同的 Windows 版本中保持不变。我的猜测是他们会的,因为太多的程序会崩溃,但这只是纯粹的猜测。

The problem is that when you do it this way you get a cached version of the icon, the first one that the system loaded. That will be the large sized icon, typically 32x32. It matters not what size you specify.

What you can do is find the ID of the desired resource in user32.dll and use something like this:

LoadImage(GetModuleHandle('user32'), MAKEINTRESOURCE(103), IMAGE_ICON,
    16, 16, LR_DEFAULTCOLOR);

You would be better to call GetSystemMetrics(SM_CXSMICON) to get hold of the icon size rather than to hard code 16, but you probably already know that.

I'm not sure where you get the resource IDs from for the resources in user32, or even if they is any guarantee that they will stay constant across different Windows versions. My guess is that they will because too many programs would break, but that's just pure guesswork.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文