none
Refresh icon cache

    Question

  • Hi all,
    I recently started developing my first C# application which has one single purpose: changing the recycle bin icon. I thought this would be a straight-forward process, but is it giving me the headache. I can easily update the registry containing the icon for the recycle bin. The problem is when i want to restore the default recycle bin icon it kinda "stucks". The icon will change to the default icon, but when I trash some files, the icon wont update to the full recycle bin icon. I have to manually right-click->refresh. I've tried a lot of things like deleting the icon cache file, using SendMessageTimeout and SHChangeNotify. Nothing seems to work. Can you help me? This is what i'm trying with at the moment: 

    [System.Runtime.InteropServices.DllImport("User32.dll")]
    public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
    [System.Runtime.InteropServices.DllImport("User32.dll")]
    public static extern long SendMessageTimeout(int hWnd, int Msg, int wParam, int lParam, int fuFlags, int uTimeout, out int lpdwResult);
    [System.Runtime.InteropServices.DllImport("Shell32.dll")]
    private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
    
    private const int SPI_SETICONS = 0x0058;
    private const int SPIF_UPDATEINIFILE = 0x1;
    private const int SPIF_SENDWININICHANGE = 0x2;
    private const int HWND_BROADCAST = 0xffff;
    private const int WM_SETTINGCHANGE = 0x001A;
    private const int SMTO_ABORTIFHUNG = 0x0002;
    private const int SPI_SETNONCLIENTMETRICS = 0x0002;
    
    SystemParametersInfo(SPI_SETICONS, 0, null, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
    
    int res = 0;
    RegistryKey iconSizeKey = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop\\WindowMetrics", true);
    int iconSize = Int16.Parse((string)iconSizeKey.GetValue("Shell Icon Size"));
    int newIconSize = iconSize - 1;
    iconSizeKey.SetValue("Shell Icon Size", newIconSize, RegistryValueKind.String);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, out res);
    iconSizeKey.SetValue("Shell Icon Size", iconSize, RegistryValueKind.String);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, out res);
    
    SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
    SHChangeNotify(0x08000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
    SHChangeNotify(0x00008000, 0x1000, IntPtr.Zero, IntPtr.Zero);
    SHChangeNotify(0x00002000, 0x1000, IntPtr.Zero, IntPtr.Zero);
    Which refreshes the desktop, but the default recycle bin icon wont change state automatically when i trash files/empty it. Can you help me out of this big headache?

    Wednesday, April 20, 2011 6:45 PM

All replies

  • After changing the paths to the Recycle Bin icons in the registry, the following calls should be sufficient to get Windows Explorer to use the new icons when the state of the Recycle Bin changes:

            SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 5000, &Result);
            SHChangeNotify(SHCNE_ASSOCCHANGED, 0, NULL, NULL);

     

    Please open a support incident if this does not resolve the problem. Visit this link to see the various support options that are available to better meet your needs:  http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone.


    --Trevor H.
    Send files to Hotmail.com: "MS_TREVORH"
    Monday, May 02, 2011 8:10 PM