Programmatically select multiple files in windows explorer

前端 未结 8 2026
粉色の甜心
粉色の甜心 2020-11-28 11:01

I can display and select a single file in windows explorer like this:

explorer.exe /select, "c:\\path\\to\\file.txt"

However, I can

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 11:39

    This should be possible with the shell function SHOpenFolderAndSelectItems

    EDIT

    Here is some sample code showing how to use the function in C/C++, without error checking:

    //Directory to open
    ITEMIDLIST *dir = ILCreateFromPath(_T("C:\\"));
    
    //Items in directory to select
    ITEMIDLIST *item1 = ILCreateFromPath(_T("C:\\Program Files\\"));
    ITEMIDLIST *item2 = ILCreateFromPath(_T("C:\\Windows\\"));
    const ITEMIDLIST* selection[] = {item1,item2};
    UINT count = sizeof(selection) / sizeof(ITEMIDLIST);
    
    //Perform selection
    SHOpenFolderAndSelectItems(dir, count, selection, 0);
    
    //Free resources
    ILFree(dir);
    ILFree(item1);
    ILFree(item2);
    

提交回复
热议问题