The GetSaveFileName function creates a Save common dialog box that lets the user specify the drive, directory, and name of a file to save.
BOOL GetSaveFileName(
LPOPENFILENAME lpofn // address of structure with initialization
// data
);
If the user specifies a filename and clicks the OK button, the return value is nonzero. The buffer pointed to by the lpstrFile member of the OPENFILENAME structure contains the full path and filename specified by the user.
If the user cancels or closes the Save dialog box or an error occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values:
CDERR_FINDRESFAILURE | CDERR_NOHINSTANCE |
CDERR_INITIALIZATION | CDERR_NOHOOK |
CDERR_LOCKRESFAILURE | CDERR_NOTEMPLATE |
CDERR_LOADRESFAILURE | CDERR_STRUCTSIZE |
CDERR_LOADSTRFAILURE | FNERR_BUFFERTOOSMALL |
CDERR_MEMALLOCFAILURE | FNERR_INVALIDFILENAME |
CDERR_MEMLOCKFAILURE | FNERR_SUBCLASSFAILURE |
By default, Windows 95 and Windows NT version 4.0 display a new version of the Save dialog box that provides user-interface features that are similar to the Windows Explorer. You can provide an OFNHookProc hook procedure for an Explorer-style Save dialog box. To enable the hook procedure, set the OFN_EXPLORER and OFN_ENABLEHOOK flags in the Flags member of the OPENFILENAME structure and specify the address of the hook procedure in the lpfnHook member.
Windows 95 and Windows NT 4.0 continue to support the old-style Save dialog box for applications that want to maintain a user-interface consistent with the Windows 3.1 or Windows NT 3.51 user-interface. To display the old-style Save dialog box, enable an OFNHookProcOldStyle hook procedure and ensure that the OFN_EXPLORER flag is not set.
Windows CE: Not all members of the OPENFILENAME structure are defined in Windows CE. For information about the defined members, see the reference topic for the OPENFILENAME structure.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in commdlg.h.
Import Library: Use comdlg32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.
Common Dialog Box Library Overview, Common Dialog Box Functions, CommDlgExtendedError, GetOpenFilename, OFNHookProc, OFNHookProcOldStyle, OPENFILENAME