如何加载小系统图标? [英] How to load a small system icon?

查看:79
本文介绍了如何加载小系统图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我读到有关 ShGetStockIconInfo 的信息,但这只能从Vista中获得。从那时起,我仍然需要支持XP。

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

有什么想法吗?

我正在使用带有以下功能的Delphi 2010: TImage 组件。

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

推荐答案

问题是当您这样,您将获得图标的缓存版本,即系统加载的第一个图标。那将是大尺寸的图标,通常为32x32。

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.

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

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);

您最好致电 GetSystemMetrics(SM_CXSMICON)掌握图标的大小,而不是硬编码16,但是您可能已经知道。

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.

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

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.

这篇关于如何加载小系统图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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