Click here to Skip to main content
15,883,938 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I change the registry "Control Panel\\Desktop\\WindowMetrics\\Shell Icon Size" twice and using
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, (LPARAM) _T("WindowMetrics"), SMTO_ABORTIFHUNG, 5000, &dwResult);

to notify windows explorer to refresh the icon of a virtual folder. It did well in xp and vista, but in window 7 it has no reactions.

I'm using MFC.
Posted
Updated 19-Dec-10 22:55pm
v2

There is one way i dont know it is correct way or not but call this function twice can solve your problem.
I did it in my project :)

void CXYZ::RefreshIcons()
{
    CString val;
    HKEY hKey;
    LONG result = ::RegOpenKeyEx(HKEY_CURRENT_USER,
        _T("Control Panel\\Desktop\\WindowMetrics"),
        0,KEY_READ,&hKey);
    BYTE buff[256];
    ZeroMemory(buff,255);
    DWORD sz = sizeof buff;
    DWORD typ = REG_SZ;
    RegQueryValueEx(hKey,_T("Shell Icon Size"),0,&typ,buff,&sz);
    RegCloseKey(hKey);
    val = buff;
    int i = _ttoi(val);
    i++;
    val.Format(_T("%d"),i);
    result = ::RegOpenKeyEx(HKEY_CURRENT_USER,
        _T("Control Panel\\Desktop\\WindowMetrics"),
        0,KEY_WRITE,&hKey);
    RegSetValueEx(hKey,_T("Shell Icon Size"),0,REG_SZ,
        (const BYTE*)val.GetBuffer(0),val.GetLength());
    val.ReleaseBuffer();
    RegCloseKey(hKey);
    ::SendMessageTimeout(HWND_BROADCAST ,
        WM_SETTINGCHANGE,0,0,SPI_SETNONCLIENTMETRICS,1000,NULL);

    i = _ttoi(val);
    i--;
    val.Format(_T("%d"),i);
    result = ::RegOpenKeyEx(HKEY_CURRENT_USER,
        _T("Control Panel\\Desktop\\WindowMetrics"),
        0,KEY_WRITE,&hKey);
    RegSetValueEx(hKey,_T("Shell Icon Size"),0,REG_SZ,
        (const BYTE*)val.GetBuffer(0),val.GetLength());
    val.ReleaseBuffer();
    RegCloseKey(hKey);
    ::SendMessageTimeout(HWND_BROADCAST ,
        WM_SETTINGCHANGE,0,0,SPI_SETNONCLIENTMETRICS,1000,NULL);
}


This code is working fine on Window7 and Vista.
 
Share this answer
 
v2
Comments
chishui 21-Dec-10 2:42am    
My code is almost the same as yours, but in win7, the icon of my virtual folder in "My Computer" does not change but its thumbnail has changed. So weird~. 3x anyway.
ShilpiP 21-Dec-10 4:15am    
Did you check if you restart your computer than the icon of virtual folder changed ??
Nobody knows?
I spent all day without figuring it out...
 
Share this answer
 
Have you ever tried the SHChangeNotify function?
 
Share this answer
 
I have the same problem when I SignIn windows7 with Adminstrator. I have tried the Answer 1, but the problem is still not solved.

But if i switch the user to Guest, everything is just fine....why?
 
Share this answer
 
v2
finally, this problem had been solved by using "SHChangeNotify". I was misleaded by "SendMessageTimeout(HWND_BROADCAST,WM_SETTINGCHANGE"...
 
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