C++ – How to change the icon in taskbar using windows api

ciconswinapi

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

Best Answer

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);
Related Topic