2

Using LoadImage I changed the icon of all the windows in a group. However the group icon does not change. How can I get the corresponding group to a window and set its icon?

enter image description here

ekad
  • 13,718
  • 26
  • 42
  • 44
Noitidart
  • 30,310
  • 26
  • 103
  • 267
  • Note to self: Research [System.AppUserModel.RelaunchIconResource](http://msdn.microsoft.com/en-us/library/windows/desktop/dd391573%28v=vs.85%29.aspx) to set the PINNED icon programatically. To set NON-pinned icon I still need to research. – Noitidart Jun 25 '14 at 03:19

2 Answers2

1

The group icon comes from the EXE file itself (in the case of multiple EXEs contributing to the same group, I imagine the taskbar has some algorithm to decide which EXE to pull the icon from). There is no official API to change the group icon. You would have to manipulate the Taskbar directly, which is not impossible but not trivial either.

Update: I just came across the following answer, maybe it will help you:

https://stackoverflow.com/a/219128/65863

Update: Apparently the Registry value in the above link only applies if the app is pinned to the Taskbar.

Community
  • 1
  • 1
Remy Lebeau
  • 454,445
  • 28
  • 366
  • 620
  • As best I can tell, the algorithm is rather trivial: it just picks the first one. – Cody Gray Jun 18 '14 at 00:35
  • That site is for WinXP, tried but im getting to handle returned when i run the same code on Win7. @CodyGray can you please link me to the algo, because i have set all the icons with `LoadImage` yet its not taking the icon of the first group :( – Noitidart Jun 18 '14 at 02:21
  • @Noitidart: Cody meant it uses the icon of the first EXE file in the group, not the first window in the group. Again, the group icon comes from the resources of an EXE file, which you cannot change while the EXE is running. – Remy Lebeau Jun 18 '14 at 07:00
  • Ohhhh dang, so theres no way to make it use the icon of the first window? :( The registry edit you put above is nice, it works if it's pinned, but if its unpinned it doesnt work. Your link to http://w-shadow.com/blog/2006/10/01/manipulating-taskbar-buttons/ is for WinXP only correct? Is there anything for Win7? – Noitidart Jun 18 '14 at 08:27
  • Apparently not. The internal implementation of the Taskbar changed in Win7, it no longer uses a standard Toolbar, the buttons are now custom drawn pictures instead. – Remy Lebeau Jun 18 '14 at 14:36
  • Accepted ansewr on the update. But re update, im having some issues: I added the `HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\firefoxe.exe` [IMAGE LINK](http://img.photobucket.com/albums/v135/noitidart/set20reg20val20in20HkEY_LOCAL_MACHI_zpsd9a5bfb9.png) AND `HKEY_CURRENT_USER\SOFTWARE\Classes\Applications\firefox.exe` [IMAGE LINK](http://img.photobucket.com/albums/v135/noitidart/set20reg20val20in20HkEY_CURRENT_USE_zpsd61734a8.png) and added `TaskbarGroupIcon` and set it to the path of an icon i had. But the icon is not taking. Please see images linked. I even tried restarting the comp. – Noitidart Jun 18 '14 at 20:55
  • Apparently the Registry value only applies if your app is pinned to the Taskbar. – Remy Lebeau Jun 18 '14 at 21:12
  • I tried pinning and unpinning it still didn't take. But when its unpinned it should take of the first window (i know u mentioned first exe) but this site here mentions: Registry entries of `DefaultIcon`, `TaskbarGroupIcon`, and `UseExecutableForTaskbarGroupIcon`. [LINK](http://msdn.microsoft.com/en-us/library/windows/desktop/ee872121%28v=vs.85%29.aspx) I can't figure out how to work these registry entries do you know if they will work? – Noitidart Jun 18 '14 at 22:04
1

Your issue is this: The icon does infact take the icon of the first WINDOW, not exe. HOWEVER, after setting the icons, you have to right click on the icon in the taskbar, then pin it, then unpin it. On unpin the taskbar icon now takes the first windows icon.

I don't know how to programatically do this to maybe @RemyLebeau knows. Maybe setClassLongPtr? Not sure.

Now when it's pinned you want to make it use the same icon, so set the registry value like @RemyLebeau suggested.

Also I don't know how to explain this, but after unpinning, and the icon takes, if you open the jump list, the icon reverts back to the exe's icon. This may be fixed with the registry setting for pinned icon, I'm not sure.

Wow so Win7 taskbar is so tweakish.

Edit: I tried setting my registry values and the icon didnt work. It might have to do something with: the registry entires that i found for TaskbarGroupIcon all had a data value ending with a comma and a number (ex: ,-4 in %SystemRoot%\System32\imageres.dll,-4)

  • "value ending with a comma and a number" - that is how you refer to a specific icon resource in the file if you do not want to use the file's default icon resource. – Remy Lebeau Jun 18 '14 at 23:36
  • I see. My path as well as topic authors image was to a `.ico` file so then no need for numbers. – user3749566 Jun 18 '14 at 23:49
  • `.ico` files can have multiple icons in them, in which case the number is an index. For an executable, the number is a resource id instead. – Remy Lebeau Jun 19 '14 at 00:28
  • Thanks I verify that pinning/unpinning an ininitally unpinned changed icon does make the taskbar take the icon. I'll investigate that function. @RemyLebeau does the index start with 0? Becaues I also used .ico without comma so maybe thats why nothing showed huh? Can we use .png? – Noitidart Jun 19 '14 at 02:02