InWindows provides some general dialogs, such as the file selection dialog box.,
Color Selection dialog box,
Font selection dialog box.
InIn MFC, CFileDialog, CColorDialog, and CFontDialog are used. Generally, you do not need to derive a new class because the base class already provides common functions. In addition, after the dialog box is created and waits for the completion of the dialog box, you can use the member function to obtain the user's selection in the dialog box.
Use of the CFileDialog file selection dialog box: First, construct an object and provide corresponding parameters. The constructor prototype is as follows:
CFileDialog: CFileDialog (BOOL bOpenFileDialog, LPCTSTR success = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = Success | fail, LPCTSTR lpszFilter = NULL, CWnd * pParentWnd = NULL ); the parameters have the following meanings:
- 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.
- LpszFilter is the most important parameter. It specifies the available file type and the corresponding extension. The parameter format is as follows:
"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 |. files of the same type can be separated by the extension; separated by |, and ended with |.
- PParentWnd is the parent window pointer.
The create file dialog box can be used.DoModal (), you can use the following function to get the user to choose after the return:
- CString CFileDialog: GetPathName () to obtain the complete file name, including the directory name and extension c: estest1.txt
- CString CFileDialog: Ge