我如何可以重复使用的应用程序图标从我的应用程序中,所以我不必嵌入了两次(一次为应用程序图标,一次用于内部使用)?

有帮助吗?

解决方案

您可以读取它通过P /互操作回调。它是这样的:

static Icon GetAppIcon() {
    var fileName = Assembly.GetEntryAssembly().Location
    System.IntPtr hLibrary = NativeMethods.LoadLibrary(fileName);
    if (!hLibrary.Equals(System.IntPtr.Zero)) {
        System.IntPtr hIcon = NativeMethods.LoadIcon(hLibrary, "#32512");
        if (!hIcon.Equals(System.IntPtr.Zero)) {
            return Icon.FromHandle(hIcon);
        }
    }
    return null; //no icon was retrieved
}

此外,天然签名是:

private static class NativeMethods {
    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    static extern internal IntPtr LoadIcon(IntPtr hInstance, string lpIconName);

    [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
     static extern internal IntPtr LoadLibrary(string lpFileName);
}

其他提示

看来最容易使用 Icon.ExtractAssociatedIcon ,在此相关的问题概括: 避免重复图标资源在.NET(C#)项目

scroll top