[英]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
,但这带有一个警告:资源管理器无法正确更新其视图,即使您告诉它使用F5或Ctrl + 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_RENAMEFOLDER
, SHCNE_RENAMEITEM
, SHCNE_UPDATEDIR
, SHCNE_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.