The cfiledialog class encapsulates common Windows File dialogs. The common file dialog box provides a simple file opening and file storage dialog box that is consistent with the Windows Standard.
Prototype:
explicit CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL, DWORD dwSize = 0, BOOL bVistaStyle = TRUE);
Parameter meaning:
If bopenfiledialog is set to true, the open dialog box is displayed. If it is set to false, the SAVE dialog file dialog box is displayed.
Lpszdefext specifies the default file extension.
Lpszfilename specifies the default file name.
Dwflags indicates some specific styles. (Default ofn_hidereadonly | ofn_overwriteprompt)
Lpszfilter indicates the available file type and the corresponding extension.
Pparentwnd is the parent window pointer.
Example:
Cfiledialog DLG (true, "TXT", "*. txt", ofn_filemustexist | ofn_hidereadonly, "Text Document (*. txt) | *. txt | ");
Member functions:
In the create file dialog box, you can use domodal (). After the result is returned, you can use the following function to get the user to choose from:
Cstring cfiledialog: getpathname () to obtain the complete file name, including the directory name and extension c: \ test \ test1.txt
Cstring cfiledialog: getfilename () to obtain the complete file name, including the extension test1.txt.
Cstring cfiledialog: getextname () to obtain the complete file extension, for example, txt
Cstring cfiledialog: getfiletitle () to get the complete file name, excluding the directory name and extension such as test1
Position cfiledialog: getstartposition () gets the first file location when multiple files are selected.
Cstring cfiledialog: getnextpathname (Position & Pos) gets the next file location when multiple files are selected, and returns the current file name at the same time. However, you must have already called position cfiledialog: getstartposition () to obtain the initial position variable.
Example:
Cfiledialog DLG (true, "TXT ","*. TXT ", ofn_filemustexist | ofn_hidereadonly," Text Document (*. TXT) | *. TXT | "); cstring filepathname; If (DLG. domodal () = idok) {filepathname = DLG. getpathname ();}
Lpszfilter format:
"Chart files (*. xlc) | *. xlc | worksheet files (*. XLS) | *. XLS | data files (*. xlc ;*. XLS) | *. xlc ;*. XLS | all files (*. *) | *. * | ";
The file type description and extension are separated by |. the extensions of files of the same type can be used. The extensions are separated by |, and the end is specified by |.