windows 在资源管理器中的文件图标上添加状态图标,例如 .NET 中的 Dropbox 或 SVN
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8383668/
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
Add status icons over file icons in Explorer, like Dropbox or SVN in .NET
提问by Anton Alexandrenok
I'm writing a Windows service application in C# with FileSystemWatcher
.
我正在用 C# 编写一个 Windows 服务应用程序FileSystemWatcher
。
How can I add status icons to files and folders in Windows Explorer similar to how Dropbox or SVN do it?
如何向 Windows 资源管理器中的文件和文件夹添加状态图标,类似于 Dropbox 或 SVN 的做法?
回答by Marco
回答by 2GDev
I've never play with this, but I think it's the right way.
我从来没有玩过这个,但我认为这是正确的方法。
First make the folder a System Folder, then create a Desktop.ini file and apply the change inside.
首先将该文件夹设为系统文件夹,然后创建一个 Desktop.ini 文件并在其中应用更改。
[.ShellClassInfo]
[email protected],-12690
IconFile=%SystemRoot%\system32\SHELL32.dll
IconIndex=-238
回答by Firen
For anyone still interessted in this question:
对于仍然对这个问题感兴趣的任何人:
Hereis a codeproject link which describes the process in great detail.
这是一个代码项目链接,其中详细描述了该过程。
It uses the SharpShelllibrary, which can also be found on nuget.
它使用SharpShell库,也可以在 nuget 上找到。
Code, from the codeproject, looks something like that:
来自 codeproject 的代码看起来像这样:
[ComVisible(true)]
public class ReadOnlyFileIconOverlayHandler : SharpIconOverlayHandler
{
protected override int GetPriority()
{
// The read only icon overlay is very low priority.
return 90;
}
protected override bool CanShowOverlay(string path, FILE_ATTRIBUTE attributes)
{
try
{
// Get the file attributes.
var fileAttributes = new FileInfo(path);
// Return true if the file is read only, meaning we'll show the overlay.
return fileAttributes.IsReadOnly;
}
catch (Exception) { return false; }
}
protected override System.Drawing.Icon GetOverlayIcon()
{
// Return the read only icon.
return Properties.Resources.ReadOnly;
}
}