Windows API one-day training (93) getsavefilename Function

Source: Internet
Author: User
Windows API one-day training (93) getsavefilename Function

The previous section describes how to open the Select File Read dialog box. When the software you design requires users to choose to save the file, they need to select their desired file name to save it. Then you need to use the save file dialog box, that is, the API function getsavefilename. The following shows how to use this API function.

The getsavefilename function declaration is as follows:

Wincommdlgapi bool apientry getsavefilenamea (lpopenfilenamea );
Wincommdlgapi bool apientry getsavefilenamew (lpopenfilenamew );
# Ifdef Unicode
# Define getsavefilename getsavefilenamew
# Else
# Define getsavefilename getsavefilenamea
# Endif //! Unicode

An example of calling a function is as follows:
#001 // obtain the name of the file to be saved by the user.
#002 // Cai junsheng 2007/12/25 QQ: 9073204 Shenzhen
#003 void testgetsavefilename (void)
#004 {
#005 //
#006 openfilename ofn; // structure of the public dialog box.
#007 tchar szfile [max_path]; // Save the buffer for obtaining the file name.
#008
#009 // initialize the select file dialog box.
#010 zeromemory (& ofn, sizeof (ofn ));
#011 ofn. lstructsize = sizeof (ofn );
#012 ofn. hwndowner = m_hwnd;
#013 ofn. lpstrfile = szfile;
#014
#015 //
#016 ofn. lpstrfile [0] = _ T ('/0 ');
#017 ofn. nmaxfile = sizeof (szfile );
#018 ofn. lpstrfilter = _ T ("All/0 *. */0 text/0 *. txt/0 ");
#019 ofn. nfilterindex = 1;
#020 ofn. lpstrfiletitle = NULL;
#021 ofn. nmaxfiletitle = 0;
#022 ofn. lpstrinitialdir = NULL;
#023 ofn. Flags = ofn_showhelp | ofn_overwriteprompt;
#024
#025 // The select file dialog box is displayed.
#026 if (getsavefilename (& ofn ))
#027 {
#028 // display the selected file.
#029 outputdebugstring (szfile );
#030 outputdebugstring (_ T ("/R/N "));
#031}
#032}

Related Article

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.