Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

c++ - Custom folder icons with desktop.ini & instant refreshing

I am tasked with creating a book-keeping program that tracks some statistics of when files and folders are read. Similar to Google Drive and TortoiseSVN, the folder and file icons should reflect certain changes. For instance, a USB with files that haven't been viewed on a certain computer have an 'x', whereas viewed files get a 'o'.

I can track file usage with this Windows API, and icons (as well as some other nice options) can be changed by the desktop.ini files [1,2,3,4].

While manually messing around with desktop.ini files, I've successfully changed icons, descriptions, and other fun stuff. The problem is that the new changes don't update until Windows parses the desktop.ini file again. This tends to happen inconsistently between a few seconds to several minutes. F5 refreshes do not force a reparse, but will update the image if a reparse has occurred.

How do I force Windows to reparse desktop.ini files both manually and (more importantly) in a C++ program?

Is there an alternative C++ Windows API that can change folder icons immidiately?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you edit desktop.ini, it Explorer won't refresh automatically. Use SHGetSetFolderCustomSettings to write to it:

SHFOLDERCUSTOMSETTINGS fcs = {0};
fcs.dwSize = sizeof(SHFOLDERCUSTOMSETTINGS);
fcs.dwMask = FCSM_ICONFILE;
fcs.pszIconFile = iconPath;
fcs.cchIconFile = 0;
fcs.iIconIndex = iconIndex;
SHGetSetFolderCustomSettings(&fcs, folderPath, FCS_FORCEWRITE);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...