Export (0) Print
Expand All

GetOpenFileNameEx

Send Feedback

This function creates a system-defined dialog box that shows a grid of thumbnails, enabling the user to choose a picture or video.

BOOL GetOpenFileNameEx(
  LPOPENFILENAMEEX lpofn
);

Parameters

lpofn
[in] Pointer to an OPENFILENAMEEX structure that contains information used to initialize the dialog. When GetOpenFileNameEx returns, this structure contains information about the user's file selection.

Return Values

Nonzero indicates that the user specified a file name. The buffer pointed to by the lpstrFile member of the OPENFILENAMEEX structure contains the full path and filename specified by the user.

Zero indicates that the user canceled or closed the dialog or that an error occurred. To get extended error information, call GetLastError function. Error values which may be returned include:

Return Value Description
ERROR_SUCCESS The user canceled the dialog.
ERROR_OUTOFMEMORY Operation ran out of memory.
ERROR_INVALID_PARAMETER An invalid argument was specified.
ERROR_INSUFFICIENT_BUFFER This error indicates that the buffer pointed to by lpstrFile was too small. In this case, the first two bytes of the buffer contain the required buffer size in characters.

Code Example

The following code example demonstrates how to use GetOpenFileNameEx.

Note   To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.
BOOL UseFilePicker(HWND hwndOwner)
{
    TCHAR    szFile[MAX_PATH];
    OPENFILENAMEEX  ofnex = {0};

    ofnex.lStructSize     = sizeof(ofnex);
    ofnex.hwndOwner       = hwndOwner;
    ofnex.lpstrFile       = szFile;
    ofnex.nMaxFile        = sizeof(szFile)/sizeof(szFile[0]);
    ofnex.lpstrFilter     = TEXT("All Files (*.*)\0*.*\0");
    ofnex.lpstrTitle      = TEXT("Thumbnail View");

    // Show thumbnails of files that are not DRM protected
    ofnex.ExFlags         = OFN_EXFLAG_THUMBNAILVIEW | OFN_EXFLAG_HIDEDRMPROTECTED;
    ofnex.lpstrInitialDir = NULL;

    return GetOpenFileNameEx(&ofnex);
}


Code Example

The following code example displays a dialog in which the user may select only files of type '*.BMP'. The function returns TRUE if the user selects a file, and the buffer is set to the full path and name of the selected file. If the function returns FALSE, the contents of the buffer are undefined.

Note   To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.
BOOL SelectBMP(LPTSTR pszFilename, DWORD cchBufSize)
{
  ASSERT(pszFilename);
  OPENFILENAMEEX ofn = {0};

  ofn.lStructSize     = sizeof(ofn);
  ofn.lpstrFilter     = _T("BMP Files (*.bmp)\0*.bmp\0");
  ofn.lpstrFile       = pszFilename;
  ofn.nMaxFile        = cchBufSize;
  ofn.lpstrInitialDir = _T("\\Program Files\\MyApp");
  ofn.lpstrTitle      = _T("Select a bitmap");
  ofn.ExFlags         = OFN_EXFLAG_THUMBNAILVIEW;

  return GetOpenFileNameEx(&ofn));
}

Requirements

Pocket PC: Windows Mobile 5.0 and later.
Smartphone: Windows Mobile 5.0 and later.
OS Versions: Windows CE 5.01 and later.
Header: Aygshell.h.


Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.


Show:
© 2015 Microsoft