如何在窗口上设置HICON(.ICO有多种尺寸)? [英] How to set HICON on a window (.ICO with multiple sizes)?

查看:459
本文介绍了如何在窗口上设置HICON(.ICO有多种尺寸)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义Win32窗口的应用程序图标,例如通过使用 GCL_HICON 调用 SetClassLong 并将句柄传递给图标(参见 SetClassLong功能

I would like to define the application icon of a Win32 window, e.g. through a call to SetClassLong with GCL_HICON and passing in a handle to an icon (see SetClassLong Function on MSDN).

这很好用,但我还没弄明白我应该如何加载图标(来自ICO文件)以保持所有可用尺寸(例如16x16,32x32,48x48和全尺寸PNG图标)。当我通过 LoadImage 将图标文件加载到内存中以获取 HICON 时,我必须指定我想要的尺寸(请参阅我的回复相关问题)。

This works great, but I have not figured out how I should load an icon (from an ICO file) in order to keep all available sizes (e.g. 16x16, 32x32, 48x48 and full size PNG icon). When I load the icon file through LoadImage into memory to get the HICON, I have to specify which size I want (see my reply to a related question).

我的ICO文件包含一个小尺寸的图像,应该用作窗口图标(标题栏的左上角),并且设计为非常清晰,但也应该在Alt-Tab对话框中显示更大的变体,但是......

My ICO file contains a small sized image which should be used as the window icon (top left corner of the title bar) and has been designed to be very crisp, but also larger variants which should show up in the Alt-Tab dialog, but...


  1. 加载16x16图标在标题栏中显示正确的图标,但是 - 当然 - 当我使用Alt-Tab时,它是一个丑陋的拉伸版本。并且在任务栏中显示的那个也不是很漂亮。

  1. Loading the 16x16 icon shows the proper icon in the title bar, but - of course - an ugly stretched version of it when I Alt-Tab. And the one showing up in the task bar is not very pretty either.

加载48x48图标在我的Alt-Tab时显示一个漂亮的图标,但是图标它显示在标题栏中是模糊的,因为它是48x48图标的缩小版本。

Loading the 48x48 icon shows a nice icon when I Alt-Tab, but the icon which shows up in the title bar is blurry, since it is a scaled down version of the 48x48 icon.

是有没有办法告诉Windows我的Windows有一个多尺寸的图标?是否有一些我错过的明显的API?

Is there any means of telling Windows that my Windows has a multi-sized icon? Is there some obvious API which I have missed?

推荐答案

GCL_HICON设置大图标,GCL_HICONSM设置小图标(大小)通常是32x32和16x16,但是你应该使用带有SM_CXICON和SM_CXSMICON的GetSystemMetrics来查找实际大小(对于大图标,你也可以将LR_DEFAULTSIZE传递给0大小的LoadImage))

GCL_HICON sets the "big" icon, GCL_HICONSM sets the small icon (Sizes are normally 32x32 and 16x16, but you should use GetSystemMetrics with SM_CXICON and SM_CXSMICON to find the actual size (For the large icon, you can also just pass LR_DEFAULTSIZE to LoadImage with 0 size))

这篇关于如何在窗口上设置HICON(.ICO有多种尺寸)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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