简体   繁体   English

如何使用“ SHGetSetFolderCustomSettings()”设置文件夹显示名称?

[英]How to set folder display name with e.g. “SHGetSetFolderCustomSettings()”?

Looks like SHGetSetFolderCustomSettings allows you to set an icon, a tooltip, a web view template and stuff, but I could not find how to set the LocalizedResourceName in the associated desktop.ini (see SHFOLDERCUSTOMSETTINGS structure ). 看起来SHGetSetFolderCustomSettings允许您设置图标,工具提示,Web视图模板和内容,但是我找不到如何在关联的desktop.ini设置LocalizedResourceName (请参见SHFOLDERCUSTOMSETTINGS结构 )。

Therefore I am currently writing to desktop.ini directly, however this comes with a caveat: Explorer does not properly update its views even when you tell it to refresh with F5 or Ctrl+R . 因此,我当前正在直接写到desktop.ini ,但这带有一个警告:资源管理器无法正确更新其视图,即使您告诉它使用F5Ctrl + R刷新。

This is what I want to write, using Python (though non-Python code should be less of an issue): 这就是我想使用Python编写的内容(尽管非Python代码应该没什么问题了):

[.ShellClassInfo]
LocalizedResourceName=My Folder Name
InfoTip=A customized folder

Any ideas how to set the folder name and have Explorer properly update it ? 有什么想法如何设置文件夹名称并让资源管理器正确更新它吗?

I have tried with SHChangeNotify(SHCNE_ALLEVENTS, SHCNF_PATH, path, path) , but this does not seem to update the display name (and also with SHCNE_RENAMEFOLDER , SHCNE_RENAMEITEM , SHCNE_UPDATEDIR , SHCNE_UPDATEITEM ). 我已经尝试过使用SHChangeNotify(SHCNE_ALLEVENTS, SHCNF_PATH, path, path) ,但是这似乎并没有更新显示名称(以及SHCNE_RENAMEFOLDERSHCNE_RENAMEITEMSHCNE_UPDATEDIRSHCNE_UPDATEITEM )。

(The worst approach would probably be to edit the desktop.ini twice... once directly, then with that API function... rather not what I want). (最糟糕的方法可能是两次编辑desktop.ini ,直接编辑一次,然后使用该API函数,而不是我想要的)。

About the why (I guess at least one of you will ask): 原因(我想至少你们中的一个会问):

I am storing project data using GUIDs as folder names. 我使用GUID作为文件夹名称存储项目数据。

The user should however see a friendly name that can also be used for sorting (and maybe even be able to edit it without interfering with the internal name). 但是,用户应该看到一个友好的名称,该名称也可以用于排序(甚至可以在不干扰内部名称的情况下对其进行编辑)。 Furthermore, the low-level file system layout should be backwards-compatible with older versions of the software. 此外,低级文件系统布局应与该软件的旧版本向后兼容。

Use simple call of IShellFolder.SetNameOf: 使用简单的IShellFolder.SetNameOf调用:

procedure UpdateLocalizedResourceName(const ADirectory, ANewResourceName: UnicodeString);
var
  Desktop: IShellFolder;
  Eaten: DWORD;
  DirIDList1, Child, NewChild: PItemIDList;
  Attr: DWORD;
  Folder: IShellFolder;
begin
  OleCheck(SHGetDesktopFolder(Desktop));
  try
    Attr := 0;
    OleCheck(Desktop.ParseDisplayName(0, nil, PWideChar(ADirectory), Eaten, DirIDList1, Attr));
    try
      OleCheck(SHBindToParent(DirIDList1, IShellFolder, Pointer(Folder), Child));
      try
        OleCheck(Folder.SetNameOf(0, Child, PWideChar(ANewResourceName), SHGDN_INFOLDER, NewChild));
        CoTaskMemFree(NewChild);
      finally
        Folder := nil;
      end;
    finally
      CoTaskMemFree(DirIDList1);
    end;
  finally
    Desktop := nil;
  end;
end;

UPDATE UPDATE

Important notice! 重要的提醒! LocalizedResourceName parameter must exists in desktop.ini before you call UpdateLocalizedResourceName. 在调用UpdateLocalizedResourceName之前,LocalizedResourceName参数必须存在于desktop.ini中。 Otherwise SetNameOf function fails. 否则SetNameOf函数将失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从hWnd获取Windows 10商店应用程序的“应用程序名称”(例如Edge) - How to get the “Application Name” from hWnd for Windows 10 Store Apps (e.g. Edge) 如何在Microsoft Lifecam Cinema上以编程方式设置网络摄像头参数(例如,关闭自动对焦) - How to set webcam parameters programatically on Microsoft Lifecam Cinema (e.g. switch off autofocus) 如何在Matlab中访问Windows相对路径(例如%userprofile%)? - How to access windows relative paths (e.g. %userprofile%) in matlab? 如何读取注册表资源字符串例如“@文件名,资源”? - How to read registry resource string e.g. “@filename,resource”? Windows 7中的符号(例如PowerPoint,Word) - Symbols in Windows 7 (e.g. PowerPoint, Word) Windows / CMD | 如果达到字符数该如何换行? - Windows/CMD | How to break line if e.g. character count reached? 如何直接在 Windows 注册表中更改与策略相关的内容? (例如最大密码年龄) - How do I change policy related things directly in Windows registry? (e.g. max pw age) 如何钩入Windows资源管理器(用于基于网络的文件存储,例如保管箱) - How to hook into the windows Explorer (for network based file stores, e.g. dropbox) 如何只打开特定的文件扩展名,例如.doc而不是.docx? - How to open only specific file extensions, e.g. .doc and not .docx? 如何在运行时检查操作系统版本,例如在 Windows 或 Linux 上,而不使用条件编译语句 - How to check the OS version at runtime, e.g. on Windows or Linux, without using a conditional compilation statement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM