Programmatically selecting file in explorer

后端 未结 3 1525
天涯浪人
天涯浪人 2020-12-05 03:12

In my application I can programmatically open explorer and select a file using the following code:

void BrowseToFile(LPCTSTR filename)
{
    CString strArgs;         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 03:44

    Found the answer to my question. I need to use the shell function SHOpenFolderAndSelectItems. Here is the code for the function if anybody is ever interested:

    void BrowseToFile(LPCTSTR filename)
    {
        ITEMIDLIST *pidl = ILCreateFromPath(filename);
        if(pidl) {
            SHOpenFolderAndSelectItems(pidl,0,0,0);
            ILFree(pidl);
        }
    }
    

提交回复
热议问题