如何加载与 MessageBox 在 Windows 10 上使用的图标相同的图标? [英] How can I load the same icon as used by MessageBox on Windows 10?

查看:26
本文介绍了如何加载与 MessageBox 在 Windows 10 上使用的图标相同的图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 10 上调用 LoadIcon 要求标准图标 IDI_INFORMATION 产生这个图标:

On Windows 10 calling LoadIcon asking for the standard icon IDI_INFORMATION yields this icon:

另一方面,调用 MessageBox 传递 IDI_INFORMATION 会生成一个使用此图标的对话框:

On the other hand, calling MessageBox passing IDI_INFORMATION produces a dialog that uses this icon:

如果对 LoadIcon 的明显调用没有这样做,我如何获得第二个图标?

How can I obtain the second icon, if the obvious call to LoadIcon does not do so?

推荐答案

这感觉像是 user32.dll 中的一个错误,但 Windows 8 也有同样的问题,所以我猜微软不在乎.

This feels like a bug in user32.dll but Windows 8 has the same issue so I guess Microsoft doesn't care.

您可以通过调用SHGetStockIconInfo:

You can get the flat icon used by MessageBox by calling SHGetStockIconInfo:

SHSTOCKICONINFO sii;
sii.cbSize = sizeof(sii);
if (SUCCEEDED(SHGetStockIconInfo(SIID_INFO, SHGSI_ICON|SHGSI_LARGEICON, &sii)))
{
    // Use sii.hIcon here...
    DestroyIcon(sii.hIcon);
}

SHGetStockIconInfo 是获取在 Vista 及更高版本上的 Windows UI 中使用的图标的文档化方法.大多数图标来自 imageres.dll 但你不应该认为这是这种情况...

SHGetStockIconInfo is the documented way to get icons used in the Windows UI on Vista and later. Most of the icons come from imageres.dll but you should not assume that this is the case...

这篇关于如何加载与 MessageBox 在 Windows 10 上使用的图标相同的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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