使 Windows 刷新图标缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3243317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:49:58  来源:igfitidea点击:

Make Windows refresh icon cache

windowsiconsnsiswindows-shellshell-icons

提问by Sudarshan S

I really liked the oxygen appearance of KDE SC 4. I wrote a program to apply these icons to windows. The program is written in NSIS, and is currently nearly fully functional. However, the only way I found to make Windows aware of the icon changes is to kill explorer.exe, delete the icon cache, and respawn explorer.exe. SHChangeNotifywith SHCNE_ASSOCCHANGEDseems to be unable to make Windows aware of the changes to the Control Panel icon, the My Computer icon, etc. Please suggest a better, less brutal approach to make Windows aware of these changes.

我真的很喜欢 KDE SC 4 的氧气外观。我写了一个程序来将这些图标应用到 Windows。该程序是用 NSIS 编写的,目前几乎功能齐全。但是,我发现让 Windows 知道图标更改的唯一方法是终止 explorer.exe,删除图标缓存,然后重新生成 explorer.exe。SHChangeNotifywithSHCNE_ASSOCCHANGED似乎无法让 Windows 知道对控制面板图标、我的电脑图标等的更改。请建议一种更好的、不那么残酷的方法来让 Windows 知道这些更改。

EDIT:I found a program called Icon Tweaker that appears to be able to do this, but it is closed source and so I have no idea how it does this. (IconTweaker: http://www.crystalxp.net/galerie/en.id.83-icontweaker.html)

编辑:我发现一个名为 Icon Tweaker 的程序似乎能够做到这一点,但它是封闭源代码,所以我不知道它是如何做到的。(IconTweaker:http://www.crystalxp.net/galerie/en.id.83-icontweaker.html )

EDIT:I have this working fine, thanks to Anders' reply (see below). However, I'll just put my working NSIS code here,in case someone else needs it

编辑:感谢安德斯的回复(见下文),我的工作正常。但是,我只是将我的工作 NSIS 代码放在这里,以防其他人需要它

ReadRegStr 
System::Call 'user32::SystemParametersInfo(i 0x0058,i0,i0,i2)i' ;SPI_SETICONS
HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size" IntOp
c:\Windows\System32\ie4uinit.exe -ClearIconCache
##代码## + 1 WriteRegStr HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size" ##代码## SendMessage 0xffff 0x001A 42 0 /TIMEOUT=100000 IntOp ##代码## ##代码## - 1 WriteRegStr HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size" ##代码## SendMessage 0xffff 0x001A 42 0 /TIMEOUT=100000

The $0 register is used to store the Shell Icon Sizevalue of HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics. We then increment the value and do a SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL), followed by a decrement and re-send.

$0 寄存器用于存储 的Shell Icon SizeHKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics。然后我们增加值并执行 a SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL),然后减少并重新发送。

EDIT:As a bonus, this can be used as a hack to get larger (Windows 7 size) desktop icons on Windows XP. Just double the Shell Icon Sizevalue and call SendMessage(don't perform the second change that restores the size)

编辑:作为奖励,这可以用作在 Windows XP 上获得更大(Windows 7 大小)桌面图标的技巧。只需将Shell Icon Size值加倍并调用SendMessage(不要执行恢复大小的第二次更改)

采纳答案by Anders

SystemParametersInfo() has a parameter called SPI_SETICONS that "Reloads the system icons" according to MSDN. I have never tried to use SPI_SETICONS so I don't know if it works, if you wanted to test you would use something like

SystemParametersInfo() 有一个名为 SPI_SETICONS 的参数,根据 MSDN,它“重新加载系统图标”。我从来没有尝试过使用 SPI_SETICONS 所以我不知道它是否有效,如果你想测试你会使用类似的东西

##代码##

If it turns out that this is not enough, you can bring out the big undocumented hammer:

如果事实证明这还不够,你可以拿出无证大锤:

  1. Read REG_SZ value named "Shell Icon Size" in HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics (If the value is not there, either abort or use GetSystemMetrics(SM_CXICON))
  2. Subtract 1 from the number you got from step one
  3. Write the modified entry back to the registry
  4. Call SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL)
  5. Write the number you got from step one entry back to the registry
  6. Call SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL)
  1. 读取 HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics 中名为“Shell Icon Size”的 REG_SZ 值(如果该值不存在,则中止或使用 GetSystemMetrics(SM_CXICON))
  2. 从第一步得到的数字中减去1
  3. 将修改后的条目写回注册表
  4. 调用 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL)
  5. 将您从第一步条目中获得的数字写回注册表
  6. 调用 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL)

Note that this could re-arrange the desktop icons even if "Auto Arrange" is off and possibly other things that might annoy the user!

请注意,即使“自动排列”关闭,这也可能会重新排列桌面图标,并且可能还有其他可能会惹恼用户的事情!

回答by Beno

You can just run the following command line:

您只需运行以下命令行:

##代码##

That command line will delete your cache icons without need to restart explorer

该命令行将删除您的缓存图标,而无需重新启动资源管理器