First, I'll write a program to open/Save the file dialog on VC6.0:
CString filepathname;//filename parameter definition
CFileDialog Dlg (true,null,null,ofn_hidereadonly | Ofn_overwriteprompt, "TXT Files (*.txt) |*.txt| All Files (*. *) |*.* ");
Open File
if (dlg.domodal () = = IDOK)//whether open successfully
{
Filepathname = Dlg.getpathname ();//Get file path and filename
Setdlgitemtext (idc_outputfile,filepathname);//Displays the file name in a editbox with an address of idc_outputfile
}
else//Open Failure handling
{
Turn On Failure handling
MessageBox ("Open Failed", NULL,MB_OK);
}
The above program is to deal with a "Open/Save File Dialog" program, below I will analyze the program, detailed description of the role of each parameter!
Construct an object and provide the corresponding parameters, the constructor prototype is as follows:
CFileDialog Dlg (BOOL bopenfiledialog, LPCTSTR lpszDefExt = null, LPCTSTR lpszFileName = null, DWORD dwFlags = Ofn_hiderea DOnly | Ofn_overwriteprompt, LPCTSTR lpszfilter = null, cwnd* pParentWnd = null);
The meanings of each parameter are described as follows:
Bopenfiledialog true to display the Open File dialog box, or False to display the Save 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 (*. *) |*.*| | "
Description: A ' | ' between the type description and extension of the file Separated, with the same type of file extension between the '; ' Separated by ' | ' between each file type Separate, end With ' | | ' Specified.
pParentWnd is the parent window pointer.
The Create File dialog box can use DoModal (), which can be used to get the user's choice after returning:
CString Cfiledialog::getpathname () Gets the full file name, including the directory name and extension such as: C:est est1.txt
CString Cfiledialog::getfilename () Gets the full file name, including the extension such as: Test1.txt
CString Cfiledialog::getextname () Gets the full file extension, such as: txt
CString Cfiledialog::getfiletitle () Gets the full file name, excluding the directory name and extension such as: test1
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.
MFC CFileDialog Open and save a File dialog box (GO)