如何以编程方式更改程序图标

How to change program Icon programmatically?

本文关键字:更改程序 图标 方式 编程      更新时间:2023-10-16

如何在Visual C++中以编程方式更改程序图标?我的IDE是Visual Studio 2013。

我想将图标更改为嵌入式资源图标。你知道该怎么办吗?

using System.Runtime.InteropServices;
..
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, IntPtr lParam);
struct IconHandler
{
    internal const uint WmSeticon = 0x80u;
    internal const int IconSmall = 0x0;
    internal const int IconBig = 0x1;
}
 private void Form1_Load(object sender, EventArgs e)
 {
    InitializeComponent();
    //Properties.Resources.Icon.Handle is just an .*ico file in your resources. Icons can have different sizes.
    SendMessage(Handle, IconHandler.WmSeticon, IconHandler.IconSmall, Properties.Resources.Icon.Handle);
    SendMessage(Handle, IconHandler.WmSeticon, IconHandler.IconBig, Properties.Resources.Icon.Handle);
}

如果您想更改Microsoft Visual Studio C++的程序图标,您可以:

Right Click Visual Studio 2013
1.Click "Properties"
2.Click the sub-tab "Shortcut"
3.Click "Change Icon"
4.Browse or select from the list below

完成!