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