3

I am writing a small windows application.

I want to create a installer using nsis script.

I know how to change the default application icon, start menu icon and desktop shortcut icon by using

Application icon : !define MUI_ICON "${INSTALL_ICON}"

Shortcut on start menu : CreateShortCut "$SMPROGRAMS\$StartMenuFolder\shorcutName.lnk" "$INSTDIR\executableName.exe" "" "$INSTDIR\${INSTALL_ICON}" 0

Shortcut on Desktop : CreateShortCut "$DESKTOP\shorcutName.lnk" "$INSTDIR\executableName.exe" "" "$INSTDIR\${INSTALL_ICON}" 0

But I want to also change the icon shown on the top left of the application window. And icon shown in task manager and icon shown on task bar. I think should be done using winapi.

Any help would be appreciated.

Thanks in advance

user2712201
  • 75
  • 2
  • 5

1 Answers1

3

It's important to change all icons, including the application, both small and big:

//Change both icons to the same icon handle.
SendMessage(hwnd, WM_SETICON, ICON_SMALL, hIcon);
SendMessage(hwnd, WM_SETICON, ICON_BIG, hIcon);

//This will ensure that the application icon gets changed too.
SendMessage(GetWindow(hwnd, GW_OWNER), WM_SETICON, ICON_SMALL, hIcon);
SendMessage(GetWindow(hwnd, GW_OWNER), WM_SETICON, ICON_BIG, hIcon);
Mike Weir
  • 3,094
  • 1
  • 30
  • 46
  • Hi there @Phoenix, the GetWindow GW_OWNER is always returning to me NULL (0x0). What do you mean change application icon though? Doing the first part changes the icon in the taskbar, and window. It doesnt change the taskbar icon if its pinned though. So I was just wondering what you mean by "application icon". Thanks! – Noitidart Mar 22 '15 at 06:40
  • 1
    @Noitidart I believe the icon used in Alt+Tab. There might be yet another icon to consider or does that not even work? – Mike Weir Mar 22 '15 at 16:11
  • Thanks @Phoenix I couldn't get `GW_OWNER` to give me success so it did nothing for me. In order to get it to change in the taskbar it would not work with `WM_SETICON` if it was pinned, for that situation I had to update the icon with IShellLink/IPersistFile in the pinned directories (possible in Implicit) as per this: [Detecting Application Pin State](http://stackoverflow.com/questions/28244200/detecting-application-pin-state#comment44852836_28245750). If it was not pinned I had to set icon with `SHGetPropertyStoreForWindow` in case he pins it later ater I did the `WM_SETICON`s – Noitidart Mar 24 '15 at 18:57