Introduction to the usage of CFileDialog

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/demok2010/article/details/5957523

CFileDialog the use of the File selection dialog: First construct an object and provide the corresponding parameters, the constructor prototype is as follows:
Cfiledialog::cfiledialog (BOOL bopenfiledialog, LPCTSTR lpszDefExt = null, LPCTSTR lpszFileName = null, DWORD dwFlags = of n_hidereadonly | Ofn_overwriteprompt, LPCTSTR lpszfilter = null, cwnd* pParentWnd = null), the parameter has the following meanings:

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 the most important parameter that indicates the type of file to choose from and the corresponding extension. Parameter formats such as:
"Chart Files (*.XLC) |*.xlc| Worksheet Files (*.xls) |*.xls| Data Files (*.xlc;*.xls) |*.xlc; *.xls| All Files (*. *) |*.*| | "; File type description and extension between | Delimited, can be used between extensions of the same type of file; Split, between each file type | Delimited, End with | | Specified.
pParentWnd is the parent window pointer. CString Cfiledialog::getpathname () Gets the full file name, including the directory 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 directory 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 cases where multiple files are selected, 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 related layers";
You can 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 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 by 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

Introduction to the usage of CFileDialog

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.