In MFC programming often need to use the selection of directories and select the file interface, the following summarizes the two types of dialog boxes I commonly used to generate the method:
Select Directory dialog box
Select Directory button
void Cdcpackerdlg::onbnclickeddecgen ()
{
Char Szpath[max_path]; Store the selected directory path
CString str;
ZeroMemory (szpath, sizeof (szpath));
Browseinfo bi;
Bi.hwndowner = m_hwnd;
Bi.pidlroot = NULL;
Bi.pszdisplayname = szpath;
Bi.lpsztitle = "Please select the directory to be packaged:";
bi.ulflags = 0;
BI.LPFN = NULL;
Bi.lparam = 0;
bi.iimage = 0;
Pop-up Select Directory dialog box
Lpitemidlist LP = SHBrowseForFolder (&BI);
if (LP && SHGetPathFromIDList (LP, szpath))
{
Str. Format ("Selected directory is%s", szpath);
AfxMessageBox (str);
}
Else
AfxMessageBox ("Invalid directory, please re-select");
}
Select File dialog box
CString Cdcpackerdlg::bootopendialog ()//Return the selected file name
{
CString strfile = _t ("");
CFileDialog dlgfile (TRUE, NULL, NULL, OFN_HIDEREADONLY, _t ("Describe Files (*.cfg) |*.cfg| All Files (*. *) |*.*| | "), NULL);
if (Dlgfile.domodal ())
{
strfile = Dlgfile.getpathname ();
}
return strfile;
}
Load File button
void Cdcpackerdlg::onbnclickedselectdec ()
{
Todo:add your control notification handler code here
M_strdescpath = ""; member variables of the class
Open File dialog box, select the file, and return to its path
M_strdescpath = Bootopendialog ();
}
[MFC] Select Directory dialog box and select File dialog box