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

Source: Internet
Author: User

Make a Select directory and select File dialog box, generally use the BROWSEINFO structure, as follows:

  • Browseinfo structure:
  • HWND hWndOwner, specifying a handle to the parent window of the dialog box
  • Lpcitemidlist Pidlroot, specifying the root of the open browse, if NULL, represents the desktop
  • LPSTR pszDisplayName, specifying a buffer that receives the display name of the directory selected by the user
  • LPCSTR lpsztitle, Text displayed above the tree view
  • UINT ulflags, specifying properties
  • Bffcallback LPFN, specifying a callback function, when certain events occur, the specified function is called, allowing the program to further customize the behavior of the dialog box
  • LPARAM LPARAM, if a callback function is specified, the value of the parameter is passed to the callback function
  • int IImage, the index of the icon for the folder object selected by the user in the System icon list

The following is the code implementation of the Select Directory dialog box:

void Cexchangedlg::onbrowser ()//select directory, I am here the browse button

{

Char Szpath[max_path];
CString str;

ZeroMemory (szpath,sizeof (szpath));

Browseinfo bi;
Bi.hwndowner=m_hwnd;
Bi.pidlroot=null;
Bi.pszdisplayname=szpath;
bi.lpsztitle= "Please select the desired directory:";
bi.ulflags=0;
Bi.lpfn=null;
bi.lparam=0;
bi.iimage=0;

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");

}
M_selectfile=szpath;
UpdateData (FALSE);

}

File selection Dialog Implementation code:

CString strfile=_t ("");
CFileDialog Dlgfile (True,null,null,ofn_hidereadonly,
_t ("Describe Files" (*.cfg) | *.cfg | All Files (*. *) | * * | "), NULL);
if (Dlgfile.domodal ())
{
Strfile=dlgfile.getpathname ();

}
M_selectfile=strfile; M_selectfile variables associated with a static text box in a dialog box

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