CFileDialog占用資料夾的解決方法

2021-07-25 03:40:39 字數 465 閱讀 4109

使用cfiledialog選擇檔案後發現有資料夾莫名被占用,不能刪除或重新命名。

筆者的開發環境是visual studio 2005,mfc工程。

cfiledialog並沒有直接占用資料夾,但他會改變工作目錄到所選檔案所在的資料夾,導致當前程序占用該資料夾,即使銷毀cfiledialog物件也不能恢復。

使用ofn_nochangedir風格。這是本文推薦的方法。

例:cfiledialog dlg(true, null, null, ofn_overwriteprompt | ofn_nochangedir, strfilter, this);

在第四個引數中加入ofn_nochangedir,使cfiledialog不再改變工作目錄。

選擇檔案後呼叫setcurrentdirectory設定工作目錄,具體用法和例程可參考微軟官方幫助文件,此處不再贅述。

---------eob------------

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...

CFileDialog選擇多個檔案

c 同時開啟n個檔案 void copennfiledlg onbutton1 endfor 獲取檔名 不包含字尾 採用cstring的left int count 擷取cstring中從左往右數的count個字元 中的4表示 dat 四個字元 filetitle filename.left fil...

使用CFileDialog選擇多個檔案

使用cfiledialog類並設定 ofn allowmultiselect標誌時,openfilename結構體的lpstrfile成員是乙個指向使用者申請分配的緩衝區,裡面接受所 選的路徑和檔名列表,這個列表的每一項由乙個null隔開,最末以兩個null結束。nmaxfile成員指明了緩衝區的大...