Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   Preselecting files in a CFileDialog (http://www.go4expert.com/forums/preselecting-files-cfiledialog-t24998/)

ill_comms 16Feb2011 13:10

Preselecting files in a CFileDialog
 
Just wondering how and if you can pre-select multiple files as the dialog opens? Do you place a list of them in the Initial Filename area, as I've tried this already the answer seems to be, No.
Am I missing something?

Basically I'd like a user to be able to select multiple files, I then do some checking of the filenames and if one of these checks comes back false, I want to reload this dialog with the files that the user had previously selected.

Any help would be greatly appreciated
Hayden

Code:

CFileDialog dlg(FALSE/*Open=TRUE Save=False*/,NULL/*Filename Extension*/,""/*Initial Filename*/,OFN_ENABLESIZING|OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT/*Flags*/,"All Files(*.*)|*.*||"/*Filetype Filter*/);
       
        const int nBufferSize = 128*1024; // May be excessive?
        TCHAR *szNewBuffer = new TCHAR[nBufferSize];
        memset(szNewBuffer, 0, sizeof(TCHAR) * nBufferSize);
        dlg.m_ofn.lpstrFile = szNewBuffer;
        dlg.m_ofn.nMaxFile = nBufferSize - 1;
       
        if (dlg.DoModal() == IDOK)
        {
                POSITION pos = dlg.GetStartPosition();
                CString fullpath;
                CString filenametemp;
                CString filename;
                int nLastSlashPos;

                filePaths = "";
                fileNameList = "";
               
                while (pos)
                {
                        fullpath = dlg.GetNextPathName(pos);

                        nLastSlashPos = fullpath.ReverseFind('\\');
                        if(nLastSlashPos >= 0)
                        {
                                filename = fullpath.Mid(nLastSlashPos+1);
                        }

                        if (filePaths != "")
                        {
                                filePaths = filePaths + "|";
                                fileNameList = fileNameList + " ";
                        }
                        filePaths = filePaths + fullpath;
                        fileNameList = fileNameList + '"' + filename + '"';
                }
        }



All times are GMT +5.5. The time now is 17:04.