GetSaveFileNameA function (commdlg.h)

[Starting with Windows Vista, the Open and Save As common dialog boxes have been superseded by the Common Item Dialog. We recommended that you use the Common Item Dialog API instead of these dialog boxes from the Common Dialog Box Library.]

Creates a Save dialog box that lets the user specify the drive, directory, and name of a file to save.

Syntax

BOOL GetSaveFileNameA(
  [in, out] LPOPENFILENAMEA unnamedParam1
);

Parameters

[in, out] unnamedParam1

Type: LPOPENFILENAME

A pointer to an OPENFILENAME structure that contains information used to initialize the dialog box. When GetSaveFileName returns, this structure contains information about the user's file selection.

Return value

Type: BOOL

If the user specifies a file name and clicks the OK button and the function is successful, the return value is nonzero. The buffer pointed to by the lpstrFile member of the OPENFILENAME structure contains the full path and file name specified by the user.

If the user cancels or closes the Save dialog box or an error such as the file name buffer being too small occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values:

Remarks

The Explorer-style 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 continues to support old-style Save dialog boxes for applications that want to maintain a user-interface consistent with the old-style 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.

Examples

For an example, see Creating an Enhanced Metafile.

Note

The commdlg.h header defines GetSaveFileName as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header commdlg.h (include Windows.h)
Library Comdlg32.lib
DLL Comdlg32.dll
API set ext-ms-win-shell-comdlg32-l1-1-1 (introduced in Windows 10, version 10.0.14393)

See also

CommDlgExtendedError

Common Dialog Box Library

Conceptual

GetOpenFileName

OFNHookProc

OFNHookProcOldStyle

OPENFILENAME

Reference