文件夹图标更改 [英] Folder Icon Change
本文介绍了文件夹图标更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用c#函数更改文件夹图标.它的工作正常,但问题是它是第一次工作.我的意思是我无法更改已经更改了图标的文件夹的图标.这是下面的代码:
I am changing the folder icons with c# function. Its working fine but the problem is its working for first time. I mean I am not able to change the icon for the folder for which I have changed the icon already. Here is the code below:
static void Main(string[] args)
{
LPSHFOLDERCUSTOMSETTINGS FolderSettings = new LPSHFOLDERCUSTOMSETTINGS();
FolderSettings.dwMask = 0x10;
FolderSettings.pszIconFile = @"C:\Program Files (x86)\Common Files\TortoiseOverlays\icons\XPStyle\ModifiedIcon.ico";
FolderSettings.iIconIndex = 0;
UInt32 FCS_READ = 0x00000001;
UInt32 FCS_FORCEWRITE = 0x00000002;
UInt32 FCS_WRITE = FCS_READ | FCS_FORCEWRITE;
string pszPath = @"D:\Downloaded Data";
UInt32 HRESULT = SHGetSetFolderCustomSettings(ref FolderSettings, pszPath, FCS_WRITE);
//Console.WriteLine(HRESULT.ToString("x"));
//Console.ReadLine();
}
[DllImport("Shell32.dll", CharSet = CharSet.Auto)]
static extern UInt32 SHGetSetFolderCustomSettings(ref LPSHFOLDERCUSTOMSETTINGS pfcs, string pszPath, UInt32 dwReadWrite);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
struct LPSHFOLDERCUSTOMSETTINGS
{
public UInt32 dwSize;
public UInt32 dwMask;
public IntPtr pvid;
public string pszWebViewTemplate;
public UInt32 cchWebViewTemplate;
public string pszWebViewTemplateVersion;
public string pszInfoTip;
public UInt32 cchInfoTip;
public IntPtr pclsid;
public UInt32 dwFlags;
public string pszIconFile;
public UInt32 cchIconFile;
public int iIconIndex;
public string pszLogo;
public UInt32 cchLogo;
}
可能是什么原因?
推荐答案
我也遇到过类似的问题.只需在第二次调用该函数之前删除desktop.ini文件即可.如果您要清除文件夹图标,则使用相同的方案:
I've faced with similar issue. Just remove the desktop.ini file before calling the function for the second time. The same scenario is used if you would like to clear folder icon:
- 删除desktop.ini.
- 省略以下几行:
....
FolderSettings.pszIconFile = @"{icon path}";
FolderSettings.iIconIndex = 0;
....
这篇关于文件夹图标更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文