2 façon de sélectionner le mode multi-fichiers :
Propriété :
Multiselect : true
ou directement dans le code :
openFileDialog->Multiselect = true;
Exemple d'usage :
#include <string>
using namespace std;
using namespace System::Runtime::InteropServices; //permet l'usage de Marshal::
/////////////////////////////////////////////////////////////////////
// Name : MarshalString
// Op : convert System::String into std::string
// arguments : String ^ s,
// string& os,
// ce code n'est pas de moi, malheureusement je ne me souviens plus de sa source...
/////////////////////////////////////////////////////////////////////
void MarshalString ( String ^ s, string& os )
{
using namespace Runtime::InteropServices;
const char* chars =
(const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
os = chars;
Marshal::FreeHGlobal(IntPtr((void*)chars));
}
/////////////////////////////////////////////////////////////////////
string sFileName;
int iNbr_Files;
array<String ^, 1> ^ stFilesNames = gcnew array<String ^, 1>(NBR_MAX_DE_FICHIERS);
// si la boîte de dialogue s'exécute sans erreur alors
if (openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
// Sélection de 1 ou plusieurs fichiers :
iNbr_Files = openFileDialog->FileNames->Length;
// on charge dans une table de string les noms et le path complet de chaque fichier sélectionné
for (int i=0; i<iNbr_Files; i++)
{
// méthode pour passer d'un type string à un type managé String ^
MarshalString ( openFileDialog->FileNames[i], sFileName);
stFilesNames[i] = Marshal::PtrToStringAnsi((IntPtr)(void*)sFileName.c_str());
} // for (int i=0; i<openFileDialog->FileNames->Length; i++)
} // if(openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
Aucun commentaire:
Enregistrer un commentaire