C# 更改固定任务栏图标(Windows 7)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/969033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change pinned taskbar icon (windows 7)
提问by Fran?ois
I wan't to customize the icon displayed within the windows 7 taskbar. When my app is running, I can do it by changing main window icon but, when the app is pinned, the exe's icon is displayed.
我不想自定义 Windows 7 任务栏中显示的图标。当我的应用程序运行时,我可以通过更改主窗口图标来实现,但是当应用程序被固定时,会显示 exe 的图标。
How can I set the taskbar icon for my app to an icon different from the one embedded within the exe ?
如何将我的应用程序的任务栏图标设置为与嵌入在 exe 中的图标不同的图标?
Not tried, this solutionmay work but looks dirty.
未尝试,此解决方案可能有效但看起来很脏。
Edit :
编辑 :
Our app is compiled once but depending on config file, features are enabled or not so it's a product or another. We do not want to compile one exe for each product.
我们的应用程序编译一次,但取决于配置文件,功能是否启用,因此它是一个产品或另一个。我们不想为每个产品编译一个 exe。
The solution above may not work as many instances of my app can be installed in different pathes (so you end up with the same exe file name but different icons!), is this registry key poorly designed or am I missing something?
上面的解决方案可能不起作用,因为我的应用程序的许多实例可以安装在不同的路径中(所以你最终得到相同的 exe 文件名但不同的图标!),这个注册表项是设计不当还是我遗漏了什么?
采纳答案by Igal Tabachnik
EDITThe info below is a bit obsolete; all new Windows 7 bits are now available as a managed API, available here: http://code.msdn.microsoft.com/WindowsAPICodePack
编辑下面的信息有点过时了;所有新的 Windows 7 位现在都可用作托管 API,可在此处获取:http: //code.msdn.microsoft.com/WindowsAPICodePack
There is a series of articleson the new Taskbar API by the debugging guru Sasha Goldshtein. You should have a look at the Overlay Icons and Progress Bars API.
调试大师Sasha Goldshtein 撰写了一系列关于新任务栏 API的文章。您应该查看Overlay Icons and Progress Bars API。
You can download the sample code from Windows 7 Taskbar Developer Resourceson Microsoft Code. What you're looking for is the IMClient
sample:
您可以从Microsoft Code 上的Windows 7 任务栏开发人员资源下载示例代码。您正在寻找的是IMClient
样本:
The IMClient sample demonstrates how taskbar overlay icons and taskbar progress bars can light up an application's taskbar button instead of relying on an additional dialog or on an icon in the system notification area (tray).
IMClient 示例演示了任务栏覆盖图标和任务栏进度条如何点亮应用程序的任务栏按钮,而不是依赖附加对话框或系统通知区域(托盘)中的图标。
I believe this should help you achieve what you want.
我相信这应该可以帮助你实现你想要的。
回答by Tom van Enckevort
回答by rein
You can do this by using the library called "Windows 7 Bridge" which is based on the "Windows Vista Bridge".
您可以使用基于“Windows Vista Bridge”的名为“Windows 7 Bridge”的库来执行此操作。
These are managed wrappers around all the Vista and Windows 7 native functions.
这些是围绕所有 Vista 和 Windows 7 本机功能的托管包装器。
More info can be found here
更多信息可以在这里找到
回答by Jesus Rodriguez
I don't know if I'm understanding your problem but..
我不知道我是否理解你的问题,但是..
If you create an application and put the icon property of the main window, that icon will appear in the taskbar also. But, if you pin-it to the taskbar, that icon dissapear. Am I right? If so, go to the project properties and in the application tab, put the icon that you want for the exe. Now, you will see that icon in the taskbar when pinned.
如果您创建一个应用程序并放置主窗口的图标属性,该图标也会出现在任务栏中。但是,如果您将其固定到任务栏,该图标就会消失。我对吗?如果是这样,请转到项目属性并在应用程序选项卡中,为 exe 放置所需的图标。现在,您将在固定时在任务栏中看到该图标。
I Use the same icon for both things :P
我对这两件事使用相同的图标:P
回答by Jon Grant
I can't test this right now unfortunately, but perhaps just creating a regular, good old shortcut might solve the problem? Create a shortcut to the app, change the icon, then pin the shortcut instead of the app itself?
不幸的是,我现在无法测试这个,但也许只是创建一个常规的、好的旧快捷方式可能会解决问题?创建应用程序的快捷方式,更改图标,然后固定快捷方式而不是应用程序本身?
Will check when I can next get access to my Windows 7 machine...
将检查我下次何时可以访问我的 Windows 7 机器...
回答by David Wengier
When you pin an application to the TaskBar, it simply creates a shortcut in the following directory:
当您将应用程序固定到任务栏时,它只会在以下目录中创建一个快捷方式:
C:\Users\<User Name>\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
You should be able to identify where the shortcut is (ie, get KnownFolders and work from there. UserAppData should be the one), and then using P/Invoke (IShellLink), you can alter the icon that the shortcut is setup to use. The machine might need a reboot for this to take effect, but it should work.
您应该能够确定快捷方式的位置(即,获取KnownFolders 并从那里开始工作。UserAppData 应该是其中之一),然后使用P/Invoke (IShellLink),您可以更改快捷方式设置使用的图标。机器可能需要重新启动才能生效,但它应该可以工作。
If you hold down Shift while right-clicking on the pinned application, and select Properties, you can see the Change Icon button for the shortcut. This is basically what you need to emulate with code.
如果在右键单击固定的应用程序时按住 Shift 键,然后选择“属性”,则可以看到快捷方式的“更改图标”按钮。这基本上是您需要用代码模拟的内容。
All of these things can definately be done with code, but whether you think they're any better than the registry setting is up to you.
所有这些事情都可以通过代码来完成,但是您是否认为它们比注册表设置更好取决于您。
回答by David Wengier
As far as I can tell, for some reason you can't change the icon for a program that's already pinned to the taskbar. To do it, just unpin the program, locate it in the start menu, right click - properties - change icon. then re-pin it to the taskbar, and it will have the new icon!
据我所知,出于某种原因,您无法更改已固定到任务栏的程序的图标。为此,只需取消固定程序,在开始菜单中找到它,右键单击 - 属性 - 更改图标。然后将它重新固定到任务栏,它就会有新的图标!
回答by Ephraim
Right click on the pinned icon, in the popup you see the programs title, there right click again and go to properties. There you are able to change the icon by clicking on the button "change icon". For me it needed a reboot to finish the changes.
右键单击固定图标,在弹出窗口中您会看到程序标题,再次右键单击并转到属性。在那里您可以通过单击“更改图标”按钮来更改图标。对我来说,它需要重新启动才能完成更改。
回答by Anonymous Cowherd
If you want to have a shortcut in the taskbar that goes directly to somewhere useful, such as your "My Documents" directory. The easy fix . . .
如果您想在任务栏中有一个快捷方式,可以直接转到有用的地方,例如您的“我的文档”目录。简单的修复。. .
Drop a folder into the taskbar ( which creates a shortcut to images ). Navigate to the directory where that shortcut was placed, right click on the shortcut and select "properties" to change the target. Select the "general" tab to change the name of the shortcut. The shortcut was placed here:
将文件夹放入任务栏(创建图像快捷方式)。导航到放置该快捷方式的目录,右键单击该快捷方式并选择“属性”以更改目标。选择“常规”选项卡以更改快捷方式的名称。快捷方式被放置在这里:
C:\Users[user]\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
C:\Users[用户]\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
You can navigate to this directory and edit the properties of the "images" shortcut.
您可以导航到此目录并编辑“图像”快捷方式的属性。