Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How do I call a real refresh of desktop icons?

How do I call a real refresh of desktop icons?

Scheduled Pinned Locked Moved C#
questiondesignwindows-admindata-structuressecurity
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bbranded
    wrote on last edited by
    #1

    Hello, We are using file based encryption to encrypt programs that have shortcuts on the desktop. Since these files are encrypted, the icons do not load. After loading the necessary certificates, a simple "F5 refresh" is performed (programmatically) on the desktop window; however, the icons for these previously encrypted programs do not appear. I'd like to implement relatively the same thing as Tweak UI's Rebuild Icons, but I can not figure out what it is doing. I have used Winspecter and watched the messages for the progman window. The following strike me as relevant, but I can't find any information on specifics: WM_USER + 3152 (0x00001050) WM_USER + 3212 (0x0000108c) I've also used sysinternals Process Monitor to watch file and registry access, and tweakui.exe only appears to be changing the icon size. Last, I used sysinternals Process Explorer to watch the call stack, which revealed nothing of much use. Is anyone familiar with what Tweak UI's Rebuild icons is doing? I've also tried calling WM_CLOSE on the program manager window, and WM_DESTROY; neither of which have any effect on the icons. Any input is appreciated. Thanks, Matt Brown

    A B 2 Replies Last reply
    0
    • B bbranded

      Hello, We are using file based encryption to encrypt programs that have shortcuts on the desktop. Since these files are encrypted, the icons do not load. After loading the necessary certificates, a simple "F5 refresh" is performed (programmatically) on the desktop window; however, the icons for these previously encrypted programs do not appear. I'd like to implement relatively the same thing as Tweak UI's Rebuild Icons, but I can not figure out what it is doing. I have used Winspecter and watched the messages for the progman window. The following strike me as relevant, but I can't find any information on specifics: WM_USER + 3152 (0x00001050) WM_USER + 3212 (0x0000108c) I've also used sysinternals Process Monitor to watch file and registry access, and tweakui.exe only appears to be changing the icon size. Last, I used sysinternals Process Explorer to watch the call stack, which revealed nothing of much use. Is anyone familiar with what Tweak UI's Rebuild icons is doing? I've also tried calling WM_CLOSE on the program manager window, and WM_DESTROY; neither of which have any effect on the icons. Any input is appreciated. Thanks, Matt Brown

      A Offline
      A Offline
      Alan N
      wrote on last edited by
      #2

      Hi, Try using the shell api to force the refresh. I can't actually verify the code as my desktop icons are just fine and dandy at the moment, but in a strictly non-rigorous test it makes them flash! Download the missing interop signatures for shell32 from http://www.pinvoke.net/index.aspx[^]

      \[DllImport("shell32.dll")\]
      static extern void SHChangeNotify(HChangeNotifyEventID wEventId,
                                        HChangeNotifyFlags uFlags,
                                        IntPtr dwItem1,
                                        IntPtr dwItem2);
      static void Main(string\[\] args) {
       // Refresh
        SHChangeNotify(HChangeNotifyEventID.SHCNE\_ASSOCCHANGED, 
                       HChangeNotifyFlags.SHCNF\_IDLIST, 
                       IntPtr.Zero, IntPtr.Zero);
      }
      

      Alan.

      B 3 Replies Last reply
      0
      • A Alan N

        Hi, Try using the shell api to force the refresh. I can't actually verify the code as my desktop icons are just fine and dandy at the moment, but in a strictly non-rigorous test it makes them flash! Download the missing interop signatures for shell32 from http://www.pinvoke.net/index.aspx[^]

        \[DllImport("shell32.dll")\]
        static extern void SHChangeNotify(HChangeNotifyEventID wEventId,
                                          HChangeNotifyFlags uFlags,
                                          IntPtr dwItem1,
                                          IntPtr dwItem2);
        static void Main(string\[\] args) {
         // Refresh
          SHChangeNotify(HChangeNotifyEventID.SHCNE\_ASSOCCHANGED, 
                         HChangeNotifyFlags.SHCNF\_IDLIST, 
                         IntPtr.Zero, IntPtr.Zero);
        }
        

        Alan.

        B Offline
        B Offline
        bbranded
        wrote on last edited by
        #3

        Very nice: http://msdn.microsoft.com/en-us/library/bb762118(VS.85).aspx[^] Why use the wEventIds you chose over some of the others? [edit] I tested all of them, and SHCNE_ASSOCCHANGED is the only one that causes a refresh. [/edit] Thanks very much, Matt

        modified on Friday, March 20, 2009 10:31 AM

        1 Reply Last reply
        0
        • A Alan N

          Hi, Try using the shell api to force the refresh. I can't actually verify the code as my desktop icons are just fine and dandy at the moment, but in a strictly non-rigorous test it makes them flash! Download the missing interop signatures for shell32 from http://www.pinvoke.net/index.aspx[^]

          \[DllImport("shell32.dll")\]
          static extern void SHChangeNotify(HChangeNotifyEventID wEventId,
                                            HChangeNotifyFlags uFlags,
                                            IntPtr dwItem1,
                                            IntPtr dwItem2);
          static void Main(string\[\] args) {
           // Refresh
            SHChangeNotify(HChangeNotifyEventID.SHCNE\_ASSOCCHANGED, 
                           HChangeNotifyFlags.SHCNF\_IDLIST, 
                           IntPtr.Zero, IntPtr.Zero);
          }
          

          Alan.

          B Offline
          B Offline
          bbranded
          wrote on last edited by
          #4

          For future reference, here they are: HChangeNotifyEventID[^] HChangeNotifyFlags definition[^]

          1 Reply Last reply
          0
          • A Alan N

            Hi, Try using the shell api to force the refresh. I can't actually verify the code as my desktop icons are just fine and dandy at the moment, but in a strictly non-rigorous test it makes them flash! Download the missing interop signatures for shell32 from http://www.pinvoke.net/index.aspx[^]

            \[DllImport("shell32.dll")\]
            static extern void SHChangeNotify(HChangeNotifyEventID wEventId,
                                              HChangeNotifyFlags uFlags,
                                              IntPtr dwItem1,
                                              IntPtr dwItem2);
            static void Main(string\[\] args) {
             // Refresh
              SHChangeNotify(HChangeNotifyEventID.SHCNE\_ASSOCCHANGED, 
                             HChangeNotifyFlags.SHCNF\_IDLIST, 
                             IntPtr.Zero, IntPtr.Zero);
            }
            

            Alan.

            B Offline
            B Offline
            bbranded
            wrote on last edited by
            #5

            Hello Alan, After testing, it appears that this the notification that an f5 refresh causes? Is this correct? Regardless, it doesn't seem to cause solve the problem... maybe TweakUI also clears the icon cache registry value. I'll look into this. If you have any other ideas on how to cause a refresh, it'd be appreciated. Thanks! Matt

            1 Reply Last reply
            0
            • B bbranded

              Hello, We are using file based encryption to encrypt programs that have shortcuts on the desktop. Since these files are encrypted, the icons do not load. After loading the necessary certificates, a simple "F5 refresh" is performed (programmatically) on the desktop window; however, the icons for these previously encrypted programs do not appear. I'd like to implement relatively the same thing as Tweak UI's Rebuild Icons, but I can not figure out what it is doing. I have used Winspecter and watched the messages for the progman window. The following strike me as relevant, but I can't find any information on specifics: WM_USER + 3152 (0x00001050) WM_USER + 3212 (0x0000108c) I've also used sysinternals Process Monitor to watch file and registry access, and tweakui.exe only appears to be changing the icon size. Last, I used sysinternals Process Explorer to watch the call stack, which revealed nothing of much use. Is anyone familiar with what Tweak UI's Rebuild icons is doing? I've also tried calling WM_CLOSE on the program manager window, and WM_DESTROY; neither of which have any effect on the icons. Any input is appreciated. Thanks, Matt Brown

              B Offline
              B Offline
              bbranded
              wrote on last edited by
              #6

              Take a look at: KB132668: Icons randomly change to different icons[^] dealing with the shell icon cache[^]. The KB article explains that you can change color depth to rebuild the shell icon cache. The second link is interesting as it explains an way to interact with the icon cache. By the way, this is the solution: Observing registry access of tweakui.exe revealed access to a registry values: HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\ reg_sz: Shell Icon Size First Rebuild Icon Cache reads the Shell Icon Size value, then writes a value of 4, then must run the shell32.dll function SendMessageTimeout, then write the original value to Shell Icon Size. Here is more information from dealing with the shell icon cache[^]:

              You can force a full cache flush by manually changing the the icon size yourself to something
              one pixel smaller, broadcasting WM_SETTINGCHANGE and then setting the icon size back to normal again
              (obviously followed by another WM_SETTINGCHANGE). The message broadcast is typically done something
              like this:

              SendMessageTimeout(
              HWND_BROADCAST,
              WM_SETTINGCHANGE,
              SPI_SETNONCLIENTMETRICS,
              (LPARAM)"WindowMetrics",
              SMTO_NORMAL|SMTO_ABORTIFHUNG,
              10000, NULL);

              You alter the icon size by manually changing its value in the registry. The key to look at is:
              HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics

              The values for the icon size are Shell Icon Size and Shell Small Icon Size (both are stored as
              strings - not DWORDs). You only need to change one of them to cause the refresh to happen (typically
              the large icon size). If those values don't exist, the shell uses the SM_CXICON metric
              (GetSystemMetrics) as the default size for large icons, and half of that for the small icon size. If
              you're trying to cause a refresh and the registry entry doesn't exist, you can just assume that the
              size is set to SM_CXICON.

              There you go! Now to test and "problem" solved! Thanks for your direction Alan! Matt Brown

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups