Most of the MFC GUI based applications always deals with saving or opening data files to or from physical media. Its is a good practice, that allow the user to select location for these operations. The familiar CFileDialog() is doing the things so neatly.

The description from MSDN is like this…

Common file dialog boxes provide an easy way to implement File Open and File Save As dialog boxes (as well as other file-selection dialog boxes) in a manner consistent with Windows standards.

ok.. ??

Good ūüôā

CFileDialog is using basically for dealing with FILES.

For FOLDER based operations, for eg:selecting a folder rather than selecting a File, windows provides another dialog. Like this.

Windows provide a set of Shell functions for performing these types of operations.

We can create a simple dialog by using the following small..small code. ūüôā

    BROWSEINFO   bi; 
    ZeroMemory(&bi,   sizeof(bi)); 
    TCHAR   szDisplayName[MAX_PATH]; 
    szDisplayName[0]    =   '';  

    bi.hwndOwner        =   NULL; 
    bi.pidlRoot         =   NULL; 
    bi.pszDisplayName   =   szDisplayName; 
    bi.lpszTitle        =   _T("Please select a folder for storing received files :"); 
    bi.ulFlags          =   BIF_RETURNONLYFSDIRS;
    bi.lParam           =   NULL; 
    bi.iImage           =   0;  

    LPITEMIDLIST   pidl   =   SHBrowseForFolder(&bi);
    TCHAR   szPathName[MAX_PATH]; 
    if   (NULL   !=   pidl)
         BOOL bRet = SHGetPathFromIDList(pidl,szPathName);
         if(FALSE == bRet)

Compile the code..

Ten,Nine,Eight,Seven,Six,Five,Four,Three,Two,One,Zero, LIFT OFF…..