How to change the icon in taskbar using windows ap

2020-04-12 07:11发布

问题:

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

回答1:

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


标签: c++ winapi icons