Click here to Skip to main content
15,887,966 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all
I tried to change file association of .htm file in XP, and here is how I did it:

1. Change the associated registry key values.

2. Call SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0) to refresh the icon;

After doing these, I double clicking the .htm file, and it is opened by the browser I expected. But the icon on the desktop is not changed into the new one(e.g. from IE to Chrome). However, if I restart explorer.exe, the icon changed to the correct one.

Can anyone please tell me how to refresh the icon on desktop after changing the file association ?

Any replies from you will be appreciated, thanks.
Posted

You can use SendMessageTimeout WINAPI function, which receives the message belongs to the same queue as the current thread, the window procedure is called directly—the time-out value is ignored. The below code will help

C#
DWORD result2 = 0; 
LRESULT result = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,(LPARAM)_T("Environment"), SMTO_ABORTIFHUNG, 5000, &result2);
 
Share this answer
 
Comments
ericchan1336 27-Feb-12 21:08pm    
sorry but this does not work...
There are two solutions I found from web:
1.change the icon size in the registry then change it back, and sendmessage with
SendMessage(HWND_BROADCAST,WM_WININICHANGE,0,0);
The side effect of solution above is that it will re-arrange the icon layout on the desktop even the auto-arrange is not enabled.

2.SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
This can do the job and have no side effect at all.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900