英文:
How to change the displayed name of a folder added to IFileDialog using AddPlace
问题
I've implemented my own File Dialog using the IFileDialog interface, and I am adding Places to the file dialog. I need to change the displayed name of a place to my own text, because if I have two places that happen to have the same name, they are impossible to tell apart. For example:
- Place 1: Name = "My application files"; Path = "C:\Users\Me\OneDrive\Documents\MyAppName"
- Place 2: Name = "Shared application files"; Path = "C:\Users\Public\Documents\MyAppName"
However, Adding a place only shows the last folder name - so both these places appear under the "Application Links" heading as "MyAppName". Obviously I need to differentiate between these - ideally I would like the Place's name to be displayed.
My code to add a single Place is as follows (error checking removed for clarity):
// Code above here sets nameW to the Place name, and pathW to its full path
// These are both CStringW variables
// Create the IShellItem for the folder
CComPtr<IShellItem> folder;
SHCreateItemFromParsingName(pathW, NULL, IID_PPV_ARGS(&folder);
// This section is trying to change what is displayed... but doesn't work!
PROPVARIANT pv = {0};
PropVariantInit(&pv);
pv.vt = VT_LPWSTR;
pv.pwszVal = nameW.GetBuffer();
// Here, I have tried various other properties such as PKEY_FileDescription, PKEY_FolderNameDisplay, etc.
SHSetTemporaryPropertyForItem(folder, PKEY_FileName, pv);
// Add the place
_FileDialog->AddPlace(folder, FDAP_TOP);
英文:
I've implemented my own File Dialog using the IFileDialog interface, and I am adding Places to the file dialog. I need to change the displayed name of a place to my own text, because if I have two places that happen to have the same name, they are impossible to tell apart. For example:
- Place 1: Name = "My application files"; Path = "C:\Users\Me\OneDrive\Documents\MyAppName"
- Place 2: Name = "Shared application files"; Path = "C:\Users\Public\Documents\MyAppName"
However, Adding a place only shows the last folder name - so both these places appear under the "Application Links" heading as "MyAppName". Obviously I need to differentiate between these - ideally I would like the Place's name to be displayed.
My code to add a single Place is as follows (error checking removed for clarity):
// Code above here sets nameW to the Place name, and pathW to its full path
// These are both CStringW variables
// Create the IShellItem for the folder
CComPtr<IShellItem> folder;
SHCreateItemFromParsingName(pathW, NULL, IID_PPV_ARGS(&folder);
// This section is trying to change what is displayed... but doesn't work!
PROPVARIANT pv = {0};
PropVariantInit(&pv);
pv.vt = VT_LPWSTR;
pv.pwszVal = nameW.GetBuffer();
// Here, I have tried various other properties such as PKEY_FileDescription, PKEY_FolderNameDisplay, etc.
SHSetTemporaryPropertyForItem(folder, PKEY_FileName, pv);
// Add the place
_FileDialog->AddPlace(folder, FDAP_TOP);
Can anyone tell me if / how I can do this? Thanks!
答案1
得分: 1
根据AddPlace()文档:
SHSetTemporaryPropertyForItem
可用于在由psi
参数表示的项目上设置临时的**PKEY_ItemNameDisplay
**属性。此属性的值将用于替代项目的UI名称。
因此,将PKEY_FileName
更改为PKEY_ItemNameDisplay
。
英文:
Per the AddPlace() documentation:
> SHSetTemporaryPropertyForItem
can be used to set a temporary PKEY_ItemNameDisplay
property on the item represented by the psi
parameter. The value for this property will be used in place of the item's UI name.
So, change PKEY_FileName
to PKEY_ItemNameDisplay
instead.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论