16

I searching function something like OpenFileDialog on .NET but on win32, i can't find this function on this name on msdn and i remember this function exists.

Can anyone give me name?

Greetings,

Svisstack
  • 16,203
  • 6
  • 66
  • 100

2 Answers2

22

I believe you are looking for the GetOpenFileName.

Casey
  • 10,297
  • 11
  • 59
  • 88
YWE
  • 2,849
  • 28
  • 42
8
//make sure this is commented out in all code (usually stdafx.h)
// #define WIN32_LEAN_AND_MEAN 

#include <windows.h>

OPENFILENAME ofn;       // common dialog box structure
TCHAR szFile[260] = { 0 };       // if using TCHAR macros

// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = _T("All\0*.*\0Text\0*.TXT\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

if (GetOpenFileName(&ofn) == TRUE)
{
    // use ofn.lpstrFile
}

Taken from Displaying Open File Dialog using WinApi

Artem Moroz
  • 119
  • 1
  • 5