資源簡介
打開一個資源管理器并選中多個目標(文件、文件夾)。在國內網站搜索很久沒有找到相關代碼,后來在一個網站上找到了使用SHOpenFolderAndSelectitems函數來打開資源管理器,但是只能選中一個目標,因此在他的基礎上測試并修改實現了所需功能。

代碼片段和文件信息
//?OpenFolderAndSelectItems.cpp:?implementation?of?the?COpenFolderAndSelectItems?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“OpenFolderAndSelectItems.h“
#include?
#include?
#include?
#pragma?comment(lib“shlwapi“)
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
COpenFolderAndSelectItems::COpenFolderAndSelectItems()
{
}
COpenFolderAndSelectItems::~COpenFolderAndSelectItems()
{
}
BOOL?COpenFolderAndSelectItems::IsPathExist(CString?const&?csPath)
{
CString?cs(csPath);
BOOL?bNoExist?=?access(cs.GetBuffer(cs.GetLength())?0)==-1;//驗證是否未存在的路徑
cs.ReleaseBuffer();
return?!bNoExist;
}
UINT?COpenFolderAndSelectItems::CssToList(CString?const&?cstrTYPE_LIST_CSTR?&strlistCString?csSplit)
{
if?(cstr.GetLength()>0)
{
int?nStart?=?0;
int?nTemp?=?-1;
while?(nStart>=0?&&?nStart {
nTemp?=?cstr.Find(csSplitnStart);
if?(nTemp<0)
{
nTemp?=?cstr.GetLength();
}
if?(nTemp>=nStart)
{
strlist.push_back(cstr.Mid(nStartnTemp-nStart));
}
nStart?=?nTemp+1;
}
}
return?strlist.size();
}
UINT?COpenFolderAndSelectItems::CsRemoveRepeat(CString?&cstrSrcTCHAR?tcSub)
{
int?i?=?0;
bool?bStartFind?=?false;
for?(i=cstrSrc.GetLength()-1;i>=0;i--)
{
if?(cstrSrc.GetAt(i)==tcSub)
{
if?(bStartFind)
{
cstrSrc.Delete(i);
}
bStartFind?=?true;
}
else
{
bStartFind?=?false;
}
}
return?cstrSrc.GetLength();
}
//?打開文件夾并選中項目項目可能是文件也可能是文件夾
BOOL?COpenFolderAndSelectItems::OpenAndSelect(CString?const&?csPath?TYPE_LIST_CSTR?const&?listFileNames)
{
//路徑轉換csPath為空或不包含“:”代表以桌面為起始路徑:
CString?csPathEx(csPath);
if?(csPath.FindOneOf(“:“)<0?||?csPath.GetLength()==0)
{
TCHAR?tcDesctop[255];
SHGetSpecialFolderPath(0tcDesctopCSIDL_DESKTOPDIRECTORY0);
csPathEx?=?tcDesctop;
csPathEx?+=?“\\“?+?csPath;
}
//將“/”換為“\”,因為PathCombine()函數只識別“..\而不識別“../”:
csPathEx.Replace(“/““\\“);
//刪除多余的“\“否則會導致TSHOpenFolderAndSelectItems()函數崩潰:
CsRemoveRepeat(csPathEx‘\\‘);
//相對路徑轉換為絕對路徑因為TSHOpenFolderAndSelectItems()不識別“..\”等符號:
if?(csPathEx.FindOneOf(“..“))
{
char?lpszDest[MAX_PATH]?=?{0};
PathCombine(lpszDestNULLcsPathEx);
csPathEx?=?lpszDest;
}
//判斷路徑是否存在,如果不存在會導致TSHOpenFolderAndSelectItems()函數崩潰:
if?(!IsPathExist(csPathEx))
{
return?FALSE;
}
//如果項目列表為空則直接打開csPath所在目錄,否則TSHOpenFolderAndSelectItems()函數將打開上一級目錄:
if?(listFileNames.size()==0)
{
ShellExecute(NULL?“open“?csPathEx?NULL?NULLSW_NORMAL);
return?TRUE;
}
//打開路徑:
BOOL?bReturn?=?FALSE;
HRESULT?hres?=?-1;
IShelllink?*psl?=?NULL;
ITEMIDLIST?*pidl?=?NULL;
CoIniti
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5083??2015-05-30?09:08??MyLibrary\OpenFolderAndSelectItems.cpp
?????文件???????1744??2015-05-29?12:21??MyLibrary\OpenFolderAndSelectItems.h
?????文件??????35716??2015-05-25?18:51??OpenFolder\OpenFolder.aps
?????文件???????1262??2015-05-30?09:53??OpenFolder\OpenFolder.clw
?????文件???????2115??2015-05-26?15:12??OpenFolder\OpenFolder.cpp
?????文件???????4410??2015-05-30?10:03??OpenFolder\OpenFolder.dsp
?????文件????????545??2015-05-25?15:27??OpenFolder\OpenFolder.dsw
?????文件???????1366??2015-05-26?15:03??OpenFolder\OpenFolder.h
?????文件??????91136??2015-05-30?10:05??OpenFolder\OpenFolder.ncb
?????文件??????49664??2015-05-30?10:05??OpenFolder\OpenFolder.opt
?????文件???????1819??2015-05-30?10:04??OpenFolder\OpenFolder.plg
?????文件???????5444??2015-05-25?18:51??OpenFolder\OpenFolder.rc
?????文件???????4838??2015-05-30?10:03??OpenFolder\OpenFolderDlg.cpp
?????文件???????1401??2015-05-25?15:35??OpenFolder\OpenFolderDlg.h
?????文件???????3651??2015-05-25?15:27??OpenFolder\ReadMe.txt
?????文件???????1078??2015-05-25?15:27??OpenFolder\res\OpenFolder.ico
?????文件????????402??2015-05-25?15:27??OpenFolder\res\OpenFolder.rc2
?????文件????????780??2015-05-25?15:30??OpenFolder\resource.h
?????文件????????212??2015-05-25?15:27??OpenFolder\StdAfx.cpp
?????文件???????1054??2015-05-25?15:27??OpenFolder\StdAfx.h
?????文件??????24576??2015-05-30?10:04??OpenFolder.exe
?????目錄??????????0??2015-05-30?10:03??OpenFolder\Debug
?????目錄??????????0??2015-05-30?10:05??OpenFolder\Release
?????目錄??????????0??2015-05-30?10:01??OpenFolder\res
?????目錄??????????0??2015-05-30?10:01??MyLibrary
?????目錄??????????0??2015-05-30?10:05??OpenFolder
-----------?---------??----------?-----??----
???????????????238296????????????????????26
- 上一篇:RevolutionSlider漢化包
- 下一篇:libiconv.so
評論
共有 條評論