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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 + '"';
		}
	}
Instead of doing this, wouldnt be better to store filenames that passes the checks first time and just add new selected files on second CFileDialog after passing your checks ?
Of course, you also need to check for duplicates.
Topic archived. No new replies allowed.