使Windows刷新图标缓存 [英] Make Windows refresh icon cache
问题描述
我真的很喜欢KDE SC 4的氧气外观。我写了一个程序将这些图标应用到windows。该程序是用NSIS编写的,目前几乎完全正常运行。但是,我发现让Windows了解图标更改的唯一方法是杀死explorer.exe,删除图标缓存,并重新生成explorer.exe。带有 SHCNE_ASSOCCHANGED
的 SHChangeNotify
似乎无法让Windows知道对控制面板图标,我的电脑图标的更改请建议一种更好,更少野蛮的方法让Windows了解这些变化。
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. SHChangeNotify
with SHCNE_ASSOCCHANGED
seems 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.
编辑:我找到了一个名为Icon Tweaker的程序似乎能够做到这一点,但它是封闭源,所以我不知道它是如何做到这一点。 (IconTweaker: http://www.crystalxp.net/galerie/en .id.83-icontweaker.html )
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)
编辑:由于安德斯的回复,我的工作正常(请参阅下面)。但是,我会把我工作的NSIS代码放在这里,以防其他人需要它
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
ReadRegStr $0 HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size"
IntOp $0 $0 + 1
WriteRegStr HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size" $0
SendMessage 0xffff 0x001A 42 0 /TIMEOUT=100000
IntOp $0 $0 - 1
WriteRegStr HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size" $0
SendMessage 0xffff 0x001A 42 0 /TIMEOUT=100000
$ 0寄存器用于存储 Shell图标大小
HKEY_CURRENT_USER \Control Panel \Desktop \ Windows Metrics
的值。然后我们递增值并执行 SendMessageTimeout(HWND_BROADCAST,WM_SETTINGCHANGE,SPI_SETNONCLIENTMETRICS,0,SMTO_ABORTIFHUNG,100000,NULL)
,然后递减并重新发送。
The $0 register is used to store the Shell Icon Size
value 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.
编辑:作为奖励,这可以用作在Windows XP上获得更大(Windows 7大小)桌面图标的黑客。只需加倍 Shell图标大小
值并调用 SendMessage
(不执行恢复大小的第二个更改)
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 Size
value and call SendMessage
(don't perform the second change that restores the size)
推荐答案
SystemParametersInfo ()有一个名为SPI_SETICONS的参数,根据MSDN重新加载系统图标。我从来没有尝试使用SPI_SETICONS所以我不知道它是否有效,如果你想测试你会使用像
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
System::Call 'user32::SystemParametersInfo(i 0x0058,i0,i0,i2)i' ;SPI_SETICONS
如果事实证明这还不够,你可以拿出大的无证锤子:
If it turns out that this is not enough, you can bring out the big undocumented hammer:
- 读取名为Shell的REG_SZ值HKEY_CURRENT_USER \Control Panel \Desktop \WindowMetrics中的图标大小(如果值不存在,则中止或使用GetSystemMetrics(SM_CXICON))
- 从您获得的数字中减去1从第一步开始
- 将修改后的条目写回注册表
- 调用SendMessageTimeout(HWND_BROADCAST,WM_SETTINGCHANGE,SPI_SETNONCLIENTMETRICS,0,SMTO_ABORTIFHUNG,100000,NULL)
- 将第一步条目中的数字写回注册表
- 调用SendMessageTimeout(HWND_BROADCAST,WM_SETTINGCHANGE,SPI_SETNONCLIENTMETRI CS,0,SMTO_ABORTIFHUNG,100000,NULL)
- 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))
- Subtract 1 from the number you got from step one
- Write the modified entry back to the registry
- Call SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL)
- Write the number you got from step one entry back to the registry
- Call 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!
这篇关于使Windows刷新图标缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!