Open/save file dialog box in MFC: cfiledialog

Source: Internet
Author: User
CfiledialogUse of the file selection dialog box: first, construct an object and provide corresponding parameters. The constructor prototype is as follows:
Cfiledialog: cfiledialog
);

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.

Dwsize

The size ofOpenfilenameStructure. this value is dependent on the operating system version, so MFC can determine the appropriate kind of dialog box to create (for example, new Windows 2000 dialogs as opposed to NT4 dialogs ). the default size of 0 means that the MFC code will determine the proper dialog box size to use based on the operating system version on which the program is run.

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: est est1.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.

For example

{
Cstring
Filepathname;
Cfiledialog DLG (true); // true indicates the open dialog box, and false indicates the Save As dialog box // DLG. m_ofn.lpstrinitialdir = _ T ("D: \"); // The default directory D disk (DLG. domodal () = idok)
Filepathname = DLG. getpathname ();
}
Related information: Several member functions used by cfiledialog to retrieve file names:
Assume that the selected file is C: windowstest. EXE.
Then:
(1) getpathname (); get the full name of the file name, including the complete path. Retrieve C: windowstest. exe
(2) getfiletitle (); get the full name of the file: Test. exe
(3) getfilename (); Retrieve Test
(4) getfileext (); obtain the extension exe

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.