Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

c++ - How to change the icon in taskbar using windows api

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$StartMenuFoldershorcutName.lnk" "$INSTDIRexecutableName.exe" "" "$INSTDIR${INSTALL_ICON}" 0

Shortcut on Desktop : CreateShortCut "$DESKTOPshorcutName.lnk" "$INSTDIRexecutableName.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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...