[C++ / commdlg.h] Répertoire courant OPENFILENAME

Résolu
GrosTony Messages postés 14 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 25 août 2005 - 20 déc. 2004 à 16:57
GrosTony Messages postés 14 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 25 août 2005 - 20 déc. 2004 à 18:41
Salut @ tous,

Dans le cadre d'un projet en cours, je doit gérer des enregistrements et chargement de fichier et je n'arrive pas à changer le répertoire courant, voici le morceau de code concerné:

void gestionMenuFichier(int selection) {
  char szFileName[MAX_PATH] = "";
  char repertoireCourant[MAX_PATH];
  ostringstream msg, title;
  OPENFILENAME ofn;
  GetCurrentDirectory(MAX_PATH,repertoireCourant);
  strcat(repertoireCourant,"\\nuages\");
  ofn.lpstrInitialDir = repertoireCourant;
  MessageBox(NULL,ofn.lpstrInitialDir,"ofn.lpstrInitialDir",MB_OK|MB_ICONEXCLAMATION);
  
  switch (selection) {
    // Ouvrir     
    case 11 : 
       ZeroMemory(&ofn, sizeof(ofn));
       ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
       ofn.hwndOwner = NULL;
       ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
       ofn.lpstrFile = szFileName;
       ofn.nMaxFile = MAX_PATH;
       ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
       ofn.lpstrDefExt = "txt";
       if(GetOpenFileName(&ofn))
       {
        // Pour l'instant simplement affichier le nom du fichier
            msg << "Fichier à charger: " << szFileName;
        title << "Charger";
        MessageBox(NULL,msg.str().c_str(),title.str().c_str(),MB_OK|MB_ICONEXCLAMATION);
       }
       break;
    // Enregistrer     
    case 12 : 
       ZeroMemory(&ofn, sizeof(ofn));
       ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
       ofn.hwndOwner = NULL;
       ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
       ofn.lpstrFile = szFileName;
       ofn.nMaxFile = MAX_PATH;
       ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT;
       ofn.lpstrDefExt = "txt";
       if(GetSaveFileName(&ofn))
       {
        // Pour l'instant simplement affichier le nom du fichier
        msg << "Fichier ouvert: " << szFileName;
        title << "Fichier ouvert";
        MessageBox(NULL,msg.str().c_str(),title.str().c_str(),MB_OK|MB_ICONEXCLAMATION);
       }
  }
  glutPostRedisplay();
}


Voici ce qu'affiche la première MessageBox (avec la chaine de caractère repertoireCourant):

ce qui est bien celui que je veux.

Et voici le dialogue OPENFILENAME (qui n'est pas dans le bon repertoire):

Est-ce que quelqu'un aurait une idée svp.
Merci.

2 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
20 déc. 2004 à 17:19
Je vois:
ZeroMemory(&ofn, sizeof(ofn));
avant appel de GetOpenFileName() donc dossier que tu avais mis dans ofn est perdu.

ciao...
BruNews, MVP VC++
3
GrosTony Messages postés 14 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 25 août 2005
20 déc. 2004 à 18:41
Merci,

Les joies du copier/coller les yeux fermés :blush) .

Maintenant ça marche :big) , merci beaucoups.

++
0
Rejoignez-nous