When I change the icon in my shortcut, why doesn’t it update on the screen?

Raymond Chen

Raymond

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 IShell­Link::Set­Icon­Location? In desperation, we added

    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);

but that didn’t help. Did we get the flags to SHChange­Notification wrong?”

The property sheet does use the IShell­Link::Set­Icon­Location 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 IPersist­File that they used to load the shortcut, or they can use Query­Interface to get a new pointer.

The SHCNE_ASSOC­CHANGED 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

Comments are closed.