将不同的任务栏图标设置为标题栏中显示的图标(C#)?

发布于 2024-09-29 20:48:04 字数 138 浏览 0 评论 0原文

我的应用程序图标有深色和浅色版本;深色版本在灰色表面(例如 Windows XP 任务栏)上效果最佳,浅色版本在标题栏中作为图标效果最佳。

有没有一种方法可以将任务栏中的图标设置为与 C# 表单中使用的图标不同的图标(P/Invoke 就可以)?

I have both dark and light versions of my application icon; the dark version works best on gray surfaces such as Windows XP taskbar, where the light version works best as an icon in the titlebar.

Is there a way I can set the icon in the taskbar to a different icon than the one used in my form in C# (P/Invoke is fine)?

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

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

发布评论

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

评论(2

红玫瑰 2024-10-06 20:48:05

使用 ICON_SMALL 和 ICON_BIG 参数的不同图标句柄将 WM_SETICON 消息发送到表单:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);

private const uint WM_SETICON = 0x80u;
private const int ICON_SMALL = 0;
private const int ICON_BIG = 1;

public MyForm()
{
    InitializeComponent();

    SendMessage(this.Handle, WM_SETICON, ICON_SMALL, Properties.Resources.IconSmall.Handle);
    SendMessage(this.Handle, WM_SETICON, ICON_BIG, Properties.Resources.IconBig.Handle);
}

Send the WM_SETICON message to your form with different icon handles for the ICON_SMALL and the ICON_BIG parameter:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, IntPtr lParam);

private const uint WM_SETICON = 0x80u;
private const int ICON_SMALL = 0;
private const int ICON_BIG = 1;

public MyForm()
{
    InitializeComponent();

    SendMessage(this.Handle, WM_SETICON, ICON_SMALL, Properties.Resources.IconSmall.Handle);
    SendMessage(this.Handle, WM_SETICON, ICON_BIG, Properties.Resources.IconBig.Handle);
}
寄人书 2024-10-06 20:48:05

我知道这是一个老问题,但我在尝试实现同样的目标时遇到了它,是的,你可以做到这一点,至少在 Windows 7/8 上。

事实证明,ICO 文件不仅仅包含一张图像,它还包含 9 种不同分辨率的 9 个不同图像:

  • 16x16
  • 24x24
  • 32x32
  • 48x48
  • 64x64
  • 72x72
  • 80x80
  • 96x96
  • 128x128

在 Windows 7 和 8 上,64x64 图像用于任务栏,而16x16 图像用于位于表单左上角的图标。

您可以使用 Greenfish Icon Editor Pro 之类的工具(我不为他们工作,或者任何东西,这不是插件!)将它们作为两个单独的图像,然后将此 *.ico 文件正常添加到 Visual Studio 中的 Windows 窗体/WPF 窗体中。

最终结果如下所示:

WPF

如您所见,我的 WPF 应用程序有两个单独的图标,一个在任务栏中,另一个在任务栏中表格上。

I know this is an old question but I came across it when trying to achieve the same thing, and well yes you can do this, on Windows 7/8 at least.

It turns out an ICO file doesn't just contain one image, it contains 9 different images at 9 different resolutions:

  • 16x16
  • 24x24
  • 32x32
  • 48x48
  • 64x64
  • 72x72
  • 80x80
  • 96x96
  • 128x128

On Windows 7 and 8, the 64x64 image is used on the taskbar, and the 16x16 image is used on the icon which is placed on the top left hand corner of your form.

You can use a tool like Greenfish Icon Editor Pro (I don't work for them or anything, this isn't a plug!) to have these as two seperate images, and then add this *.ico file as normal to your Windows Form/WPF form in Visual Studio.

The end result is shown below:

WPF

As you can see my WPF application has two seperate icons, one in the taskbar and another on the form.

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