Comment Re:Native GUI app development is a pain (Score 1) 330
Okay, found the example in my code archives:
CFileDialog fDlg( TRUE, NULL, NULL,
OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER,
NULL, this );
DWORD MAXFILE = 2562;
fDlg.m_ofn.nMaxFile = MAXFILE;
fDlg.m_ofn.lpstrFile = new wchar_t[MAXFILE];
fDlg.m_ofn.lpstrFile[0] = NULL;
fDlg.m_ofn.lpstrFilter = L"Images\0*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff\0"
L"All files\0*.*\0";
#ifdef NDEBUG
fDlg.m_ofn.Flags&= ~OFN_ENABLEHOOK;
#endif
if (fDlg.DoModal()==IDOK){
for (POSITION pos = fDlg.GetStartPosition();pos != NULL;)
{
CString fname= fDlg.GetNextPathName(pos);//here's the filename!
}
}
More or less the same stuff in Qt:
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setNameFilter(trUtf8("Splits (*.000 *.001)"));
QStringList fileNames;
if (dialog.exec())
fileNames = dialog.selectedFiles();//List of files is returned
The WinAPI version required a lot of trial and error to get the input parameters correct. Plus, there's no way of stating "allocate as much memory as required for output", so you have to pre-allocate memory and hope the user doesn't select too many files. This issue turns a "lots of boilerplate code pasted from MSDN" inconvenience into a real problem with no solution except for displaying an error message.