如何在 Windows 中即时刷新文件夹图标 [英] How to refresh the folder icon instantly in Windows

查看:59
本文介绍了如何在 Windows 中即时刷新文件夹图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在编写一个小工具,需要立即刷新文件夹图标.
众所周知,在 Windows 中,我们可以通过以下步骤手动修改文件夹图标:

I am now programming a small tool and need to refresh the folder icon instantly.
As we know, in Windows, we could modify folder icons by the following steps manually:

  1. 右键单击文件夹
  2. 选择自定义"标签
  3. 点击更改图标"

我也知道如何设置desktop.ini文件来修改它的图标.但是刷新确实需要很长时间(大约 30 秒).

I also know how to set the desktop.ini file to modify its icon. But it takes really a long time to refresh (about 30 seconds).

我想知道是否有一种通用的方法可以立即解决它,无论是使用 C/C++ 还是脚本.还是 Windows 从来没有提供方法?

I wanna know if there is a common way to solve it instantly no matter using C/C++ or script. Or Windows never provides a way?

如果可能,欢迎任何代码.

If possible, any code is welcome.

推荐答案

这个小 C 程序将完成这项工作:

This small C program will do the job:

#include <windows.h>
#include <ShlObj.h>

const char folderpath[] = "C:\\Your-Folder";

int main() {
  SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, folderPath, NULL);
}

folderpath 是要更新图标的文件夹的完整路径以下操作序列在这里工作正常(Windows 10 64 位):

folderpath is the full path to the folder whose icon is to be updated Following sequence of operations works fine here (Windows 10 64 bits):

Desktop.ini 文件

[.ShellClassInfo]
IconResource=C:\Windows\System32\SHELL32.dll,12

  1. 创建文件夹 X
  2. 将上面的 Desktop.ini 文件复制到文件夹中.X文件夹的图标不会改变
  3. 运行上面的小 C 程序
  4. 新图标显示在 X 文件夹中
  5. 删除第 2 点创建的 Deskop.ini 文件.X 文件夹的图标不会改变
  6. 运行上面的小 C 程序
  7. 原文件夹图标显示在X文件夹上

检查SHChangeNotify 函数了解更多详情.

Check the SHChangeNotify function for more details.

这篇关于如何在 Windows 中即时刷新文件夹图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆