【问题标题】:wxDirDialog Returns the Wrong Directory on VistawxDirDialog 在 Vista 上返回错误的目录
【发布时间】:2014-03-14 12:03:09
【问题描述】:

我最近在visual studio 2013下将以下代码移植到wx3.0:

void PanelFileControl::on_retrieve_clicked(wxCommandEvent &event)
{
   if(!chosen_files.empty())
   {
      Csi::ModalCounter counter;
      wxDirDialog query(
         this,
         make_wxString(my_strings[strid_choose_retrieve_dir]),
         make_wxString(wxGetApp().get_config()->get_last_prog_dir()));
      int rcd;

      query.CentreOnParent();
      rcd = query.ShowModal();
      if(rcd == wxID_OK)
      {
         // we need to generate an operation for every selected file. 
         StrAsc path(make_StrAsc(query.GetPath()));
         DlgFileControl::operations_type operations;

         if(path.last() != Csi::FileSystemObject::dir_separator())
            path.append(Csi::FileSystemObject::dir_separator());
         for(files_type::iterator fi = chosen_files.begin(); fi != chosen_files.end(); ++fi)
         {
            file_type const &file(*fi);
            StrAsc file_path(path + file.get_file_name());
            bool use_file(true);
            if(Csi::file_exists(file_path.c_str()))
            {
               OwxStringStream message;
               message << boost::format(my_strings[strid_overwrite_file_confirm].c_str()) %
                  file_path;

               wxMessageDialog overwrite_query(
                  this,
                  message.str(),
                  wxT(""),
                  wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
               int rcd;
               overwrite_query.CentreOnParent();
               rcd = overwrite_query.ShowModal();
               if(rcd != wxID_YES)
                  use_file = false;
            }
            if(use_file)
               operations.push_back(new ReceiveFileOperation(file, file_path));
         }

         // we can now display the operation dialogue
         if(!operations.empty())
         {
            DlgFileControl dialogue(this, device_name, operations);
            dialogue.show_modal();
         }
      }
   }
} // on_retrieve_clicked

在此更改之后(不需要对上面的代码进行任何更改),我收到的投诉是,如果用户选择桌面然后双击桌面上的目录,则文件保存操作会失败。这似乎是 wxDirDialog::GetPath() 产生的路径的结果,并且只在 windows vista 下看到过​​。我进行了一些测试,发现在 Vista 下,最后一个路径组件在 GetPath() 返回的字符串中被提及两次。

有人看过这个问题吗?有什么解决办法吗?

【问题讨论】:

    标签: visual-c++ wxwidgets


    【解决方案1】:

    我发现我可以通过阻止 wxDirDialog 使用 IFILEDIALOG 接口来解决这个问题。我的 ShowModal() 方法现在看起来像这样:

    int wxDirDialog::ShowModal()
    {
        WX_HOOK_MODAL_DIALOG();
    
        wxWindow* const parent = GetParent();
        WXHWND hWndParent = parent ? GetHwndOf(parent) : NULL;
    
        // Use IFileDialog under new enough Windows, it's more user-friendly.
        int rc;
    #if wxUSE_IFILEDIALOG
        if ( wxGetWinVersion() > wxWinVersion_Vista )
        {
            rc = ShowIFileDialog(hWndParent);
        }
        else
        {
            rc = wxID_NONE;
        }
    
        if ( rc == wxID_NONE )
    #endif // wxUSE_IFILEDIALOG
        {
            rc = ShowSHBrowseForFolder(hWndParent);
        }
    
        // change current working directory if asked so
        if ( rc == wxID_OK && HasFlag(wxDD_CHANGE_DIR) )
            wxSetWorkingDirectory(m_path);
    
        return rc;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-09-24
      • 1970-01-01
      • 2010-09-20
      • 2010-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      • 1970-01-01
      相关资源
      最近更新 更多