如何加载系统小图标?
我需要显示 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是,当您这样做时,您会获得图标的缓存版本,即系统加载的第一个图标。这将是大尺寸的图标,通常为 32x32。您指定的尺寸并不重要。
您可以做的是在 user32.dll 中找到所需资源的 ID 并使用类似以下内容:
您最好调用
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:
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.