About chooose a directory by using GetOpenFileNameEx RRS feed

  • Question

  • I want the user to choose a directory to save the file. I think on Mobile I also can use GetOpenFileNameEx to jump a dialog  to let user to choose or create a path.

    But after I use GetOpenFileNameEx, when the dialog jump out. I can't enter sub-directory and can't go back to up-level directory. It is very strange.

    Is this the correct way to let user choose a directory? Or should I write a dialog myself?

    Here is my sample code:
        TCHAR   szFile[MAX_PATH] = TEXT("\0");
        char    *szFileContent = NULL;
        OPENFILENAMEEX   ofn;
        DWORD dwFileSize = 0, bytesToRead = 0, bytesRead = 0;
        memset( &(ofn), 0, sizeof(ofn));
        ofn.lStructSize   = sizeof(ofn);
        ofn.hwndOwner = hDlg;
        ofn.lpstrFile = szFile;
        ofn.nMaxFile = MAX_PATH;
        //ofn.lpstrFilter = TEXT("jpg (*.jpg)\0 *.jpg\0");
        ofn.lpstrInitialDir = TEXT("\\");
        ofn.lpstrTitle = TEXT("Choose a Directory");
        ofn.Flags = OFN_EXPLORER | OFN_PROJECT;
        //get the path the user wants to open
        if (GetOpenFileNameEx(&ofn))
        } else {
            MessageBox (NULL, TEXT("Select Directory Error!"), TEXT("Error"), MB_OK);
    Thursday, February 4, 2010 1:56 AM


  • I don't think GetOpenFileName/GetOpenFileNameEx can work as a folder selection dialog. You would need to create your own dialog or use some 3rd party dialogs. Please read the following thread:

    Please mark the post that helps you, and unmark that does not. This benefits our community.
    • Marked as answer by Water Lin Tuesday, February 9, 2010 7:05 AM
    Monday, February 8, 2010 10:57 AM