在运行时更改外部exe图标 [英] Changing external exe icon at runtime

查看:114
本文介绍了在运行时更改外部exe图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的应用程序,该应用程序应该简单地复制另一个现有的可执行文件并更改其图标。 .NET是否可以实现?我问的是图标更改,复制不是问题。

I'm developing a simple application which is supposed to simply copy another existing executable file and change it's icon. Is this possible to achieve with .NET? I'm asking about icon changing, copying is not a problem.

我不知道如何以及从何处开始。我在Google上进行了搜索,但只发现了我不太熟悉的非托管C ++代码。

I have no clues on how and where to start. I've searched on Google, but found only unmanaged C++ code which I'm not very much familiar with.

这篇文章与在运行时更改当前应用程序的图标无关,而是关于更改外部应用程序的图标(在Windows资源管理器中可以看到)。

This post has nothing with changing current application's icon at runtime, rather it's about changing the icon of an external application (that's visible in Windows Explorer).

任何帮助将不胜感激。

谢谢。

推荐答案

.NET对此不提供任何支持。图标存储在.exe中嵌入的非托管资源中。您可以通过File + Open + File来查看它们,选择.exe并打开Icons节点。编号最小的图标是Windows使用的图标。

.NET has no support for this whatsoever. The icon is stored in the unmanaged resources embedded in a .exe. You can see them with File + Open + File, select the .exe and open the Icons node. The lowest numbered icon is the one Windows uses.

更新这些资源通常需要重建.exe。幸运的是,Windows API支持即时更新资源。它有一定的限制,但这对您的图标不会产生影响。您将需要BeginUpdateResource,UpdateResource和EndUpdateResource。注意它们不是易于使用,您需要知道图标资源编号。访问pinvoke.net以获得所需的声明。

Updating those resources normally requires rebuilding the .exe. Luckily the Windows API has support for updating resources on-the-fly. It has restrictions but that shouldn't affect you for icons. You'll need BeginUpdateResource, UpdateResource and EndUpdateResource. Beware that they are not easy to use, you need to know the icon resource number. Visit pinvoke.net for the declarations you will need.

这篇关于在运行时更改外部exe图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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