gpt4 book ai didi

c# - 文件夹图标更改

转载 作者:太空狗 更新时间:2023-10-30 00:55:30 24 4
gpt4 key购买 nike

我正在使用 C# 函数更改文件夹图标。它工作正常,但问题是它是第一次工作。我的意思是我无法更改我已经更改图标的文件夹的图标。这是下面的代码:

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 文件即可。如果您想清除文件夹图标,则使用相同的方案:

  1. 删除 desktop.ini。
  2. 省略以下行:

....

FolderSettings.pszIconFile = @"{icon path}";
FolderSettings.iIconIndex = 0;

....

关于c# - 文件夹图标更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9277492/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com