1. Select a directory
void Cdecryptfiledlg::onbnclickedsel () { std::wstring selecteddir; WCHAR Szdir[max_path]; ZeroMemory (szdir, sizeof(szdir)); Browseinfo bi; Bi.hwndowner = m_hwnd; Bi.pidlroot = NULL; Bi.pszdisplayname = szdir; Bi.lpsztitle = L "Please select directory:"; bi.ulflags = 0; bi.lpfn = NULL; bi.lparam = 0; bi.iimage = 0;//Select Directory LP Itemidlist LP = SHBrowseForFolder (&bi), if (LP && shgetpathfromidlist (LP, Szdir)) {Selecteddir =< c20> Szdir; Selecteddir + = L "\ \";} Setdlgitemtext (Idc_path, Selecteddir.c_str ());}
2. Dragging and dropping files
void cdecryptfiledlg::ondropfiles (hdrop hdropinfo) { int dropcount = Dragqueryfile (Hdropinfo,-1, NULL, 0); for (int i = 0; i < Dropcount; i++) { WCHAR wcstr[max_path]; Dragqueryfile (Hdropinfo, I, wcstr, MAX_PATH); string concatenation please handle setdlgitemtext (Idc_path, wcstr); } Dragfinish (Hdropinfo);}
3. Traverse a Folder
void cdecryptfiledlg::browsecurrentallfile (wstring strdir) { if(Strdir.empty ()) { return; } Else { if (strdir[strdir.length ()-1]! = L ' \ \ ') { Strdir + = l "\ \";} Strdir = Strdir + L "* *";} CFileFind Finder; Wstring strpath; BOOL bworking = Finder. FindFile (Strdir.c_str ()); While(bworking) {bworking = finder. FindNextFile (); strpath = Finder. GetFilePath (); if (finder. Isdirectory () &&! Finder. Isdots ()) {browsecurrentallfile (strpath);//Recursive call } else if (!finder. Isdirectory () &&! Finder. Isdots ()) {//strpaht is the file path to get DecryptFile (strpath); }}}
Simple code common to MFC