My .exe has a hardcoded icon, but at runtime it can load another icon from a file. It activates the icon loaded from the file by doing:
Application->Icon->LoadFromFile(filename);
in C++Builder, which boils down to the following calls to the Windows API in Delphi:
SendMessage(Handle, WM_SETICON, ICON_BIG, LPARAM(GetIconHandle));
SetClassLong(Handle, GCL_HICON, LPARAM(GetIconHandle));
If I launch my executable from C:\ , or any user directory, then the following icons are all updated correctly:
- Corner icon on the main window's title bar
- Icon in the Alt-Tab screen
- Icon on taskbar
However if I launch the exact same executable which has been copied into the folder C:\Program Files\MyApp, then the first two of those update correctly. However, the icon on the taskbar is not updated. The taskbar still shows the hardcoded icon.
Is there some sort of special protection for taskbar icons of programs launched from under C:\Program Files? Or what's going on here?
I have cleared the icon cache and it makes no difference. I have also tried adding an extra SendMessage with ICON_SMALL but that made no difference either.