[Ouverture de fichiers] répertoire
Salut à tous,
Je programme en C++ et je voudrais avoir une fonction "ouvrir un fichier" standard via API Windows. J'utilise le bout de code suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
string Menu::chooseOpenFile()
{
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
*szFile = 0; //Initialize first value
HWND hwnd=0; // owner window
HANDLE hf; // file handle
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrInitialDir = "data";
ofn.lpstrFilter = "Surface3D files\0*.s3d\0"; //"All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE)
{
return string(ofn.lpstrFile);
}
else return string("");
} |
Le problème est à la ligne
Code:
ofn.lpstrInitialDir = "data";
Quand je compile, il semble trouver le bon répertoire (qui pourtant ne se trouve pas à côté de l'exécutable mais plus haut dans la hiérarchie de fichier). Mais si après je déplace le programme, ça ne marche plus car il retient tout l'URL absolu (genre C:\Programmation\Cpp\...\...\data).
Moi je voudrais que ça marche avec un répertoire relatif ( ..\data\ ) et non absolu (genre C:\Programmation\Cpp\...\...\data). Ainsi on pourrait déplacer l'exécutable avec ses répertoires et ça marcherait encore.
J'ai essayé avec
Code:
ofn.lpstrInitialDir = "../data";
Mais ça ne marche pas :? Comment faire ? Merci d'avance :mrgreen: