#include #include using namespace std; // Must compile with -lcomdlg32 string getfilename( ) { string EMPTY = ""; string answer; OPENFILENAME ofn; // Struct for opening a file TCHAR fn[MAX_PATH+1]; // Space for storing the open file name ZeroMemory(&ofn, sizeof(OPENFILENAME)); ZeroMemory(&fn, MAX_PATH+1); ofn.lStructSize = sizeof(OPENFILENAME); ofn.lpstrFilter = _T("Image files (*.txt)\0*.TXT\0\0"); ofn.lpstrFile = fn; ofn.nMaxFile = MAX_PATH+1; ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST ; if (!GetOpenFileName(&ofn)) return EMPTY; answer = fn; return answer; } int main( ) { string name; name = getfilename( ); cout << name; return 0; }