[MFC] Select Directory dialog box and select File dialog box

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.