GetOpenFileName

  BOOL GetOpenFileName(lpofn)    
  LPOPENFILENAME lpofn; /* address of structure with initialization data */

The GetOpenFileName function creates a system-defined dialog box that makes it possible for the user to select a file to open.

Parameters

lpofn

Points to an OPENFILENAME structure that contains information used to initialize the dialog box. When the GetOpenFileName function returns, this structure contains information about the user's file selection. The OPENFILENAME structure has the following form:

#include <commdlg.h>

typedef struct tagOPENFILENAME { /* ofn */

DWORD lStructSize;

HWND hwndOwner;

HINSTANCE hInstance;

LPCSTR lpstrFilter;

LPSTR lpstrCustomFilter;

DWORD nMaxCustFilter;

DWORD nFilterIndex;

LPSTR lpstrFile;

DWORD nMaxFile;

LPSTR lpstrFileTitle;

DWORD nMaxFileTitle;

LPCSTR lpstrInitialDir;

LPCSTR lpstrTitle;

DWORD Flags;

UINT nFileOffset;

UINT nFileExtension;

LPCSTR lpstrDefExt;

LPARAM lCustData;

UINT (CALLBACK* lpfnHook) (HWND, UINT, WPARAM, LPARAM);

LPCSTR lpTemplateName;

} OPENFILENAME;

Return Value

The return value is TRUE if the user selects a file to open. It is FALSE if an error occurs, if the user chooses the Cancel button, if the user chooses the Close command on the System menu to close the dialog box, or if the buffer identified by the lpstrFile member of the OPENFILENAME structure is too small to contain the string that specifies the selected file.

Errors

Use the CommDlgExtendedError function to retrieve the error value, which may be one of the following values:

CDERR_FINDRESFAILURE
CDERR_INITIALIZATION
CDERR_LOCKRESFAILURE
CDERR_LOADRESFAILURE
CDERR_LOADSTRFAILURE
CDERR_MEMALLOCFAILURE
CDERR_MEMLOCKFAILURE
CDERR_NOHINSTANCE
CDERR_NOHOOK
CDERR_NOTEMPLATE
CDERR_STRUCTSIZE
FNERR_BUFFERTOOSMALL
FNERR_INVALIDFILENAME
FNERR_SUBCLASSFAILURE

Comments

If the hook function (to which the lpfnHook member of the OPENFILENAME structure points) processes the WM_CTLCOLOR message, this function must return a handle of the brush that should be used to paint the control background.