Exemple #1
0
  bool show(Display* parent) override {
    std::wstring filtersWStr = getFiltersForGetOpenFileName();

    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = (HWND)parent->nativeHandle();
    ofn.hInstance = GetModuleHandle(NULL);
    ofn.lpstrFilter = filtersWStr.c_str();
    ofn.nFilterIndex = m_defFilter;
    ofn.lpstrFile = &m_filename[0];
    ofn.nMaxFile = FILENAME_BUFSIZE;
    if (!m_initialDir.empty())
      ofn.lpstrInitialDir = m_initialDir.c_str();
    ofn.lpstrTitle = m_title.c_str();
    ofn.lpstrDefExt = m_defExtension.c_str();
    ofn.Flags =
      OFN_ENABLESIZING |
      OFN_EXPLORER |
      OFN_LONGNAMES |
      OFN_NOCHANGEDIR |
      OFN_PATHMUSTEXIST;

    if (!m_save)
      ofn.Flags |= OFN_FILEMUSTEXIST;
    else
      ofn.Flags |= OFN_OVERWRITEPROMPT;

    BOOL res;
    if (m_save)
      res = GetSaveFileName(&ofn);
    else
      res = GetOpenFileName(&ofn);

    if (!res) {
      DWORD err = CommDlgExtendedError();
      if (err) {
        std::vector<char> buf(1024);
        sprintf(&buf[0], "Error using GetOpen/SaveFileName Win32 API. Code: %d", err);
        she::error_message(&buf[0]);
      }
    }

    return res != FALSE;
  }
  bool show(Display* parent) override {
    std::wstring filtersWStr = getFiltersForGetOpenFileName();

    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = (HWND)parent->nativeHandle();
    ofn.hInstance = GetModuleHandle(NULL);
    ofn.lpstrFilter = filtersWStr.c_str();
    ofn.nFilterIndex = m_defFilter;
    ofn.lpstrFile = &m_filename[0];
    ofn.nMaxFile = FILENAME_BUFSIZE;
    if (!m_initialDir.empty())
      ofn.lpstrInitialDir = m_initialDir.c_str();
    ofn.lpstrTitle = m_title.c_str();
    ofn.lpstrDefExt = m_defExtension.c_str();
    ofn.Flags =
      OFN_ENABLESIZING |
      OFN_EXPLORER |
      OFN_LONGNAMES |
      OFN_NOCHANGEDIR |
      OFN_PATHMUSTEXIST;

    if (!m_save) {
      ofn.Flags |= OFN_FILEMUSTEXIST;
      if (m_multipleSelection)
        ofn.Flags |= OFN_ALLOWMULTISELECT;
    }
    else
      ofn.Flags |= OFN_OVERWRITEPROMPT;

    BOOL res;
    if (m_save)
      res = GetSaveFileName(&ofn);
    else {
      res = GetOpenFileName(&ofn);
      if (res && m_multipleSelection) {
        WCHAR* p = &m_filename[0];
        std::string path = base::to_utf8(p);

        for (p+=std::wcslen(p)+1; ; ++p) {
          if (*p) {
            WCHAR* q = p;
            for (++p; *p; ++p)
              ;

            m_filenames.push_back(
              base::join_path(path, base::to_utf8(q)));
          }
          else                  // Two null chars in a row
            break;
        }

        // Just one filename was selected
        if (m_filenames.empty())
          m_filenames.push_back(path);
      }
    }

    if (!res) {
      DWORD err = CommDlgExtendedError();
      if (err) {
        std::vector<char> buf(1024);
        sprintf(&buf[0], "Error using GetOpen/SaveFileName Win32 API. Code: %d", err);
        she::error_message(&buf[0]);
      }
    }

    return (res != FALSE);
  }