CFileDialog using the File selection dialog: First constructs an object and provides a corresponding argument to the constructor prototype, for example, the following:
Cfiledialog::cfiledialog (BOOL bopenfiledialog, LPCTSTR lpszDefExt = null, LPCTSTR lpszFileName = null, DWORD dwFlags = of n_hidereadonly | Ofn_overwriteprompt, LPCTSTR lpszfilter = null, cwnd* pParentWnd = null), the meaning of the parameters is as follows:
Bopenfiledialog true to display the Open dialog box, or False to display the Save Dialog File dialog box.
LPSZDEFEXT Specifies the default file name extension.
LPSZFILENAME Specifies the default file name.
DwFlags indicates some particular style.
Lpszfilter is one of the most important parameters. It indicates the type of file to be selected and the corresponding extension. The format of the parameters is as follows:
"Chart Files (*.XLC) |*.xlc| Worksheet Files (*.xls) |*.xls| Data Files (*.xlc;*.xls) |*.xlc; *.xls| All Files (*. *) |*.*| | "; File type description and extension between | Separated, can be used between extensions of the same type of file; Cutting, between each file type | Separated. End With | | Specified.
pParentWnd is the parent form pointer. CString Cfiledialog::getpathname () Gets the full file name, including the folder name and extension such as: C:/test/test1.txt
CString Cfiledialog::getfilename () Gets the full file name. such as: Test1
CString Cfiledialog::getextname () Gets the full file extension, such as: txt
CString Cfiledialog::getfiletitle () Gets the full file name, including the folder name and extension such as: Test1.txt
POSITION cfiledialog::getstartposition () Gets the first file location for cases where multiple files are selected.
CString cfiledialog::getnextpathname (position& Pos) Gets the next file location for multiple files selection and returns the current file name at the same time.
However, you must have already called position cfiledialog::getstartposition () to get the initial position variable.
VC + + CFileDialog read multiple files CFileDialog dlg (TRUE,
"DEM Files (*dem)",
Null
ofn_hidereadonly | Ofn_overwriteprompt | Ofn_allowmultiselect| Ofn_enablesizing,
_t ("Layer Files (*. dem;*. tiff;*. bmp;*. JPG) |*. dem;*. tiff;*. bmp;*. JPG;) | | "),
NULL);
Dlg.m_ofn.lpstrtitle= "Please load the relevant layer";
Ability to open up to 100 files
dlg.m_ofn.nMaxFile = * MAX_PATH;
Dlg.m_ofn.lpstrFile = new Tchar[dlg.m_ofn.nmaxfile];
ZeroMemory (dlg.m_ofn.lpstrFile, sizeof (TCHAR) * dlg.m_ofn.nMaxFile);
Show file dialog box, get the file name collection
int retval = dlg. DoModal ();
if (Retval==idcancel)
return false;
POSITION Pos_file;
Pos_file = dlg. GetStartPosition ();
Carray<cstring, cstring> Ary_filename;
while (pos_file! = NULL)
Ary_filename. ADD (dlg. Getnextpathname (Pos_file));
Read related files according to extension
for (int i=0; i<ary_filename. GetSize (); i++)
{
CString Str_ext;
Str_ext = Ary_filename. GetAt (i). Right (3);
if ((Str_ext = = "DEM") | | (Str_ext = = "Dem"))
{
}
else if ((Str_ext = = "TIFF") | | (Str_ext = = "TIFF"))
{
}
else if ((Str_ext = = "BMP") | | (Str_ext = = "BMP"))
{
}
else if ((Str_ext = = "JPG") | | (Str_ext = = "jpg"))
{
}
else if ((Str_ext = = "SHP") | | (Str_ext = = "shp"))
{
}
}
return True
CFileDialog Use simple Introduction