Win32打开某个文件所在的文件夹并定位

来源:互联网 发布:来肯在线进销存软件 编辑:程序博客网 时间:2024/06/05 18:00



方法一: 相同的目录会打开多次


 string str = "/select,  ";
 str+=m_pFilePath;//同一个目录
 str+=m_pFileName;    
 str+=".mp4";

 ShellExecute(NULL,"open","explorer.exe",str.c_str(),NULL,SW_SHOWNORMAL);


方法二:相同的目录只打开一次,但是需要初始化类库  CoInitialize
 
 CoInitialize(NULL);
 string str = m_pFilePath;
 str+=m_pFileName;    
 str+=".mp4";

 ITEMIDLIST* pidl = ILCreateFromPath(str.c_str());
 if(pidl)
  SHOpenFolderAndSelectItems(pidl,0,0,0);   
 CoUninitialize();

0 0