MFC CFileDialog Open and Save Files dialog box

Source: Internet
Author: User
Tags save file

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)

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.