如何使用AddPlace更改添加到IFileDialog的文件夹的显示名称

huangapple go评论62阅读模式
英文:

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&lt;IShellItem&gt; folder;
        SHCreateItemFromParsingName(pathW, NULL, IID_PPV_ARGS(&amp;folder);

        // This section is trying to change what is displayed... but doesn&#39;t work!
        PROPVARIANT pv = {0};
        PropVariantInit(&amp;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-&gt;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.

huangapple
  • 本文由 发表于 2023年5月11日 15:56:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76225298.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定