BruNews> J'crois qu'il veut utiliser les Dialogues GetOpenFileName et SaveOpenFileName ....
Buzu> Voici un exemple complet qui te permette de selectionner un fichier (c:\monfichier.txt) et d'afficher le chemin dans une editbox qui contiendra donc "c:\monfichier.txt" :
bool ChooseFile(HWND hEditBox) {
char File[MAX_PATH]; OPENFILENAME ofn;
ZeroMemory(File,sizeof(File));
ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = GetActiveWindow(); ofn.hInstance = GetModuleHandle(NULL); ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = NULL; ofn.nFilterIndex = 0; ofn.lpstrFile = File; ofn.nMaxFile = sizeof(File); ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = NULL; ofn.lpstrInitialDir = NULL; ofn.nFileOffset = NULL; ofn.nFileExtension = NULL; ofn.lpstrDefExt = "*.lst"; ofn.lCustData = NULL; ofn.lpfnHook = NULL; ofn.lpTemplateName = NULL; ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST; ofn.lpstrTitle = "Choisir le fichier à ouvrir"; ofn.lpstrFilter = "Executable (*.exe)\0*.exe\0Tous les fichiers\0*.*\0\0"; if( !GetOpenFileName( &ofn ) ) return false; else { SetWindowText(hEditBox,File); return true; }
return false; }
|
Tu n'as plus qu'a copier cette fonction dans ton programme, sans oublier son prototype si tu la mets après le WinMain();
Pour l'utiliser c'est simple, tu as juste a lui passer en parametres le handle de ta EditBox.
Exemple:
HWND hEdit1;
hEdit1 = GetDlgItem(hWnd,IDC_EDIT1); if(!ChooseFile(hEdit1)) MessageBox(hWnd,"Il y a eu une erreur!",NULL,MB_ICONSTOP);
|
La fonction retourne true si tout s'est bien passé et false dans le cas contraire.
A++ et bonne continuation...
Samir