CFileDialog多選檔案的最大數量

2022-04-04 01:27:50 字數 1344 閱讀 2983

cfiledialog這個類用來選擇檔案不錯,不過針對多選,預設的最**擇檔案數量有限,它的最大字串緩衝大小僅有260,這時候需要對它的資料成員m_ofn進理處理,如下**所示:

dword nfilenumbers = 500;    //

cfiledialog最**擇檔案數量

cfiledialog filedlg(true,

_t("txt

"),

_t("*.txt"),

ofn_filemustexist | ofn_hidereadonly |ofn_allowmultiselect,

text(

"檔案 (*.txt)|*.txt|all files (*.*)|*.*||"),

this

); position pos = 0

; cstring strfile;

tchar *pbufold = filedlg.m_ofn.lpstrfile; //

儲存舊的指標

dword dwmaxold = filedlg.m_ofn.nmaxfile; //

儲存舊的數量

filedlg.m_ofn.lpstrfile = new tchar[ nfilenumbers *max_path];

zeromemory(filedlg.m_ofn.lpstrfile,

sizeof(tchar) * nfilenumbers *max_path);

filedlg.m_ofn.nmaxfile = nfilenumbers * max_path; //

此最大數,按msdn解釋為filedlg.m_ofn.lpstrfile指向的緩衝的最大字元數

//預設是260

if (idok != filedlg.domodal()) goto

exit_onbnclickedcreatebatch;

pos =filedlg.getstartposition();

while

(pos)

exit_onbnclickedcreatebatch:

delete (filedlg.m_ofn.lpstrfile);

//清除堆記憶體

filedlg.m_ofn.lpstrfile = pbufold; //

還原之前的指標,因為沒有深入過cfiledialog原始碼分析,不清這個是否必須的,還是先還原上吧,

//說不定cfiledialog析構的時候要用上

filedlg.m_ofn.nmaxfile = dwmaxold; //

還原之前的最大數

CFileDialog實現多選

create dialog to open multiple files.cfiledialog filedlg true,null,null,ofn hidereadonly ofn overwriteprompt ofn allowmultiselect ofn explorer,t tbl檔案...

獲取GetOpenFileName多選檔名

openfilename ofn tchar szopenfilenames 80 max path tchar szpath max path tchar szfilename 80 max path tchar p intnlen 0 zeromemory ofn,sizeof ofn ofn....

CFileDialog開啟多個檔案

cfiledialog dlg true,null,ofn allowmultiselect ofn explorer,null tchar pbuffer new tchar max path 10 dlg.m ofn.lpstrfile pbuffer dlg.m ofn.nmaxfile 10...