C++ (Qt)/// Вызов окна диалога для выбора открываемого файлаQString getOpenFileName(QWidget* parent, const char* caption, const char* directory, const char* filter){ const int NAME_SIZE = 550; char fname[NAME_SIZE] = {0}; ///< буфер для имени файла bool result = false; #ifdef Q_WS_WIN OPENFILENAME ofn; ///< структура диалога открытия файла ::ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = 88; ofn.hwndOwner = (parent) ? parent -> winId() : 0; ofn.lpstrFile = fname; ofn.nMaxFile = sizeof(fname); ofn.lpstrFilter = filter; ofn.nFilterIndex = 0; ofn.lpstrFileTitle = 0; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = directory; ofn.lpstrTitle = caption; ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if(::GetOpenFileName(&ofn) == 1) result = true;#endif // Q_WS_WIN return (result) ? QString(fname) : QString("");} /// Вызов окна диалога для выбора открываемых файловQStringList getOpenFileNames(QWidget* parent, const char* caption, const char* directory, const char* filter){ const int NAME_SIZE = 5500; char fname[NAME_SIZE] = {0}; ///< буфер для имени файла QStringList list; #ifdef Q_WS_WIN OPENFILENAME ofn; ///< структура диалога открытия файла ::ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = 88; ofn.hwndOwner = (parent) ? parent -> winId() : 0; ofn.lpstrFile = fname; ofn.nMaxFile = sizeof(fname); ofn.lpstrFilter = filter; ofn.nFilterIndex = 0; ofn.lpstrFileTitle = 0; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = directory; ofn.lpstrTitle = caption; ofn.Flags = OFN_ALLOWMULTISELECT | OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if(::GetOpenFileName(&ofn) == 1) { if(ofn.nFileExtension) list << QString(fname); else if(ofn.nFileOffset) { QString path(QString(fname) + QDir::separator()), name(""); for(int i=ofn.nFileOffset, j=ofn.nFileOffset+1; fname[i]!=0 || fname[j]!=0 || j<sizeof(fname); ++i, ++j) { if(fname[i] != 0) name += QChar(fname[i]); if(fname[j] == 0) list << QString(path + name), name.clear(), ++i, ++j; if(fname[i] == 0 && fname[j] == 0) break; } } }#endif // Q_WS_WIN return list;}
C++ (Qt) ofn->Flags = (OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_EXPLORER); if (mode == QFileDialog::ExistingFile || mode == QFileDialog::ExistingFiles) ofn->Flags |= (OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST); if (mode == QFileDialog::ExistingFiles) ofn->Flags |= (OFN_ALLOWMULTISELECT); if (!(options & QFileDialog::DontConfirmOverwrite)) ofn->Flags |= OFN_OVERWRITEPROMPT;