15 ZeroMemory(&ofn,
sizeof(ofn));
16 ofn.lStructSize =
sizeof(ofn);
17 ofn.hwndOwner = parent.
handle();
18 ofn.lpstrFile = szFile;
21 ofn.lpstrFile[0] =
'\0';
22 ofn.nMaxFile =
sizeof(szFile);
23 ofn.lpstrFilter =
"All\0*.*\0Text\0*.TXT\0";
25 ofn.lpstrFileTitle = NULL;
26 ofn.nMaxFileTitle = 0;
27 ofn.lpstrInitialDir = NULL;
28 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
31 void initDir(
const std::string &dir)
33 ofn.lpstrInitialDir = dir.c_str();
35 void initFile(
const std::string &fname)
37 if( fname.length()>255)
38 throw std::runtime_error(
39 "wex::filebox fname too long");
57 ofn.lpstrFilter = fbuf;
63 ofn.lpstrDefExt = ext.c_str();
67 void title(
const std::string &fname)
69 ofn.lpstrTitle = fname.c_str();
78 if (GetOpenFileNameA(&ofn) == TRUE)
80 myfname = ofn.lpstrFile;
81 if (ofn.lpstrFile[ofn.nFileOffset - 1] == 0)
86 myfname += &ofn.lpstrFile[ofn.nFileOffset];
91 auto err = CommDlgExtendedError();
103 std::vector<std::string> ret;
104 if (GetOpenFileNameA(&ofn) == TRUE)
106 if (ofn.lpstrFile[ofn.nFileOffset - 1] != 0)
109 ret.push_back(ofn.lpstrFile);
113 std::string dir = ofn.lpstrFile;
114 int p = ofn.nFileOffset;
117 myfname = &ofn.lpstrFile[p];
120 ret.push_back(dir +
"\\" + myfname);
121 p += myfname.length() + 1;
133 if (GetSaveFileNameA(&ofn) == TRUE)
134 myfname = ofn.lpstrFile;
A popup window where used can browse folders and select a file.
Definition: filebox.h:9
std::string path() const
get filename entered by user
Definition: filebox.h:140
std::vector< std::string > openMulti()
prompt user for one or multiple files
Definition: filebox.h:101
void filter(const char *fbuf)
Set file filters.
Definition: filebox.h:54
std::string open()
prompt user for one file to open
Definition: filebox.h:76
void defaultExtension(const std::string &ext)
default extension for saved file, appended to whatever user enters
Definition: filebox.h:61
std::string save()
prompt user for folder and filename to save
Definition: filebox.h:131
The base class for all windex gui elements.
Definition: wex.h:900
HWND handle()
get window handle
Definition: wex.h:1748