Win32:在高 DPI 下在对话框中显示股票图标

发布于 2024-09-16 08:52:11 字数 829 浏览 2 评论 0原文

我有一个对话框,需要在其中显示标准信息图标。这是我的 RC 代码:

ICON    "",IDC_ICON_INFORMATION,18,70,21,20

我按如下方式处理 WM_INITDIALOG 消息:

HICON aIcn = LoadIcon(NULL, IDI_INFORMATION);
SendDlgItemMessage(m_hWnd, IDC_ICON_INFORMATION, STM_SETICON, (WPARAM) aIcn, 0);

在 96 DPI 下一切正常:静态控件显示 32x32 像素图标。

但是,当我切换到更高的 DPI 时(通过右键单击桌面,选择屏幕分辨率,然后单击放大或缩小其他项目) 图标无法缩放!由于其他所有内容都可以很好地缩放,因此该图标在视觉上看起来比相邻文本小得多。我预计在 144 DPI (150%) 下图标尺寸将为 48x48 像素。我确实通过 XML 清单将我的应用程序声明为 DPI 感知型。

最糟糕的是,当我使用自己定制的图标(也来自 RC 文件)时,一切都可以完美缩放。此外,使用 MB_ICONINFORMATION 标志调用的 MessageBox 函数也会显示图标的缩放版本。

鉴于这些想法,我做出以下假设:

  1. 具有 SS_ICON 样式的静态控件可以显示图标的缩放版本。
  2. 包含标准信息图标的图标资源具有该图标的缩放版本 (48x48)。

那我做错了什么?

I've got a dialog box where I need to display the standard Information icon. Here's my RC code:

ICON    "",IDC_ICON_INFORMATION,18,70,21,20

I process the WM_INITDIALOG message as follows:

HICON aIcn = LoadIcon(NULL, IDI_INFORMATION);
SendDlgItemMessage(m_hWnd, IDC_ICON_INFORMATION, STM_SETICON, (WPARAM) aIcn, 0);

Everything works great under 96 DPI: the static control displays a 32x32-pixel icon.

However, when I switch to higher DPI's (through right-clicking on the Desktop, choosing Screen resolution, and clicking Make or other items larger or smaller) the icon does not scale! Since everything else scales nicely, the icon looks visually much smaller than the neighboring text. I would expect that on 144 DPI (150%) the icon dimensions will be 48x48 pixels. I did declare my application as DPI-aware through an XML manifest.

The damnedest thing is that when I use my own custom-made icon (also coming from the RC file), everything scales perfectly. Furthermore, the MessageBox function called with the MB_ICONINFORMATION flag does display a scaled version of the icon, as well.

Given these thoughts, I assume of the following:

  1. The static control with the SS_ICON style can display scaled versions of icons.
  2. The icon resource that contains the standard Information icon has a scaled version of the icon (48x48).

What am I doing wrong then?

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

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

发布评论

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

评论(1

自我难过 2024-09-23 08:52:11

使用 LoadImage() 而不是 LoadIcon( ),并使用从 GetSystemMetrics(SM_CYICON) 和 GetSystemMetrics(SM_CXICON) 获取的值指定 cxDesired 和 cyDesired 参数。

或者也许只是将您的应用程序声明为 DPI 感知就足够了?您可以通过简单地创建一个文本文件使其成为清单文件来轻松尝试。
请参阅 SetProcessDPIAware API 备注部分的示例

Use LoadImage() instead of LoadIcon(), and specify the cxDesired and cyDesired params with the values you get from GetSystemMetrics(SM_CYICON) and GetSystemMetrics(SM_CXICON).

Or maybe just declaring your app as DPI aware could be enough? You can try that easily by simple creating a text file making it a manifest file.
See the example in the remarks section for the SetProcessDPIAware API

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