26

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.

How can I set the taskbar icon for my app to an icon different from the one embedded within the exe ?

Not tried, this solution may 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.

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?

Community
  • 1
  • 1
François
  • 927
  • 1
  • 7
  • 11
  • I would assume there wouldn't be support for this, only because if I pinned an icon, I'd assume that icon wouldn't change into something else later on. Overlays I could understand, but not an IE icon turning into a Firefox icon when clicked. – Will Eddins Jun 17 '09 at 20:31
  • see it: http://stackoverflow.com/questions/1285798/is-it-possible-to-change-a-console-windows-icon-from-net –  Sep 12 '12 at 12:46

9 Answers9

23

EDIT The 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

There is a series of articles on the new Taskbar API by the debugging guru Sasha Goldshtein. You should have a look at the Overlay Icons and Progress Bars API.

You can download the sample code from Windows 7 Taskbar Developer Resources on Microsoft Code. What you're looking for is the IMClient sample:

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).

alt text
(source: microsoft.co.il)

alt text
(source: microsoft.co.il)

alt text
(source: microsoft.co.il)

I believe this should help you achieve what you want.

Glorfindel
  • 19,729
  • 13
  • 67
  • 91
Igal Tabachnik
  • 30,180
  • 15
  • 86
  • 150
  • I know it, i'm already using overlay icons/pgbar in my app but overlay isn't the same thing as app icon. Overlay isn't shown when the app is pinned and closed... – François Jun 15 '09 at 09:57
16

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.

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.

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.

David Wengier
  • 9,655
  • 5
  • 35
  • 43
  • Unfortunately I can't handle it when the user himself try to pin the application. Maybe with a watch on the directory... really dirty! – François Jun 17 '09 at 12:12
  • 4
    The quick launch bar should normally be considered off limits to an app as its part of the user's preferences, thus the user should be left to manage that area. – Chris Chilvers Aug 14 '09 at 00:33
  • Excellent information even if one isn't trying to do this in code. Thanks. – mlibby Mar 11 '10 at 12:43
  • This method does require a log off/restart. Anyway to like trigger a nevent with `SetClassLongPtr` to make it refresh the icon? – Noitidart Jun 18 '14 at 02:28
1

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!

1

You can do this by using the library called "Windows 7 Bridge" which is based on the "Windows Vista Bridge".

These are managed wrappers around all the Vista and Windows 7 native functions.

More info can be found here

rein
  • 31,307
  • 23
  • 77
  • 106
1

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.

I Use the same icon for both things :P

Jesus Rodriguez
  • 11,660
  • 9
  • 59
  • 86
  • You are right for the first part. But the icon of my main window is not the same whether a config file is present or not. I want this icon to stay even when the app is pinned whithout compiling one exe for each config. – François Jun 16 '09 at 07:48
  • What do you mean with "compiling one exe for each config"? On Windows 7, the taskbar icon and the windows title icon are the same (using the Icon property on the main window). But, the pinned icon, is the .exe icon. If you have only one .exe and you want to pin-it, put an icon to that .exe and when the app is pinned, you will see that icon. In short, use the same icon for both things. – Jesus Rodriguez Jun 16 '09 at 10:12
  • I am working on 3 version of the application (lite, normal, pro). Marketing asks us to set different icons for each version. The version is determined from config + serial key and we don't want to produce one exe for each version only to change icon. I know it is possible to change the icon (see link in my question) but as it's based on the exe name, it will fail if the user has two or more version installed. I think it is not possible and we have to stay with one icon or compile many exes. – François Jun 17 '09 at 08:09
0

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...

Jon Grant
  • 10,975
  • 2
  • 33
  • 54
0

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.

Ephraim
  • 707
  • 1
  • 7
  • 14
0

Have a look at this blog. He does a series of blog posts about programming the Windows 7 taskbar, so maybe that will point you in the right direction.

Tom van Enckevort
  • 4,160
  • 1
  • 23
  • 40
-1

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

You can navigate to this directory and edit the properties of the "images" shortcut.

Anonymous Cowherd
  • 111
  • 1
  • 1
  • 7