A customer was having trouble updating the icon in one of their shortcuts. Here’s what they shared with us:
i_shell_link->SetIconLocation(icon_file.value().c_str(), 0);
“Changing the icon from the shortcut property sheet works, but it’s not working from our code. Is the shortcut property sheet using a different API from IShellLink::SetIconLocation
? In desperation, we added
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
but that didn’t help. Did we get the flags to SHChangeNotification wrong?”
The property sheet does use the IShellLink::SetIconLocation
method to change the shortcut icon. What the customer forgot was to save their changes!
i_persist_file->Save(NULL, TRUE);
where i_persist_file
is the IPersistFile
that they used to load the shortcut, or they can use QueryInterface
to get a new pointer.
The SHCNE_ASSOCCHANGED
notification is unnecessary, and in fact it’s overkill. That’s like saying, “I want to change the color of my sofa, so I’m going to demolish my house, rebuild it, and then refurnish it with a new sofa.”
If you want to send a notification to say, “Hey, I updated this file, please go refresh any data you have cached about it,” you can do a
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, fullpath, NULL);
0 comments