Select the Single file dialog box:
1 CString strfile = _t (""); 2 3 CFileDialog dlgfile (TRUE, NULL, NULL, OFN_HIDEREADONLY, _t ("Describe Files (*.jpg) |*.jpg| All Files (*. *) |*.*| | " ), NULL); 4 5 if (Dlgfile.domodal ()) 6 {7 strfile = dlgfile.getpathname (); 8 }
Select Multiple Files dialog box
1 voidCbugreportdlg::selectfiles (vector<cstring>&all_sel_files)2 {3CFileDialog dlg (TRUE, _t ("*.jpg"), NULL, ofn_allowmultiselect| ofn_hidereadonly | Ofn_filemustexist, _t ("Image Files (*.jpg) |*.jpg|"), NULL); 4Dlg.m_ofn.lpstrTitle = _t ("Select Picture"); 5 CString filename;6 if(DLG. DoModal () = =IDOK)7 { 8POSITION filenamesposition =dlg. GetStartPosition (); 9 while(Filenamesposition! =NULL)Ten { Onefilename =dlg. Getnextpathname (filenamesposition); A all_sel_files.push_back (filename); - } - } the -}
Select Folder
1 CString Cbugreportdlg::selfilepath ()2 {3TCHAR Szfolderpath[max_path] = {0}; 4CString Strfolderpath = TEXT (""); 5 6 Browseinfo Sinfo; 7:: ZeroMemory (&sinfo,sizeof(Browseinfo)); 8Sinfo.pidlroot =0; 9Sinfo.lpsztitle = _t ("Please select the processing result store path"); TenSinfo.ulflags = bif_returnonlyfsdirs| Bif_editbox|Bif_dontgobelowdomain; OneSINFO.LPFN =NULL; A - //Show Folder selection dialog box -Lpitemidlist Lpidlbrowse =:: SHBrowseForFolder (&sinfo); the if(Lpidlbrowse! =NULL) - { - //Get folder name - if(:: SHGetPathFromIDList (Lpidlbrowse,szfolderpath)) + { -Strfolderpath =Szfolderpath; + } A } at if(Lpidlbrowse! =NULL) - { - :: CoTaskMemFree (Lpidlbrowse); - } - - returnStrfolderpath; in}
WINDOWS--MFC Select File dialog box and select Folder dialog box