Bonjour,

Voila je cherche le moyen d'avoir un opendialog mais pour un dossier et non un fichier.

J'ai trouver 2/3 fonction le permettant mais pas comme je veut

Je vais mettre du code et des images sa iras plus vite que des explications

Le mieu que j'ai trouver est celui-ci :



Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
unit BrowseForFolderU;
 
interface
 
function BrowseForFolder(const browseTitle: String;
  const initialFolder: String = '';
  mayCreateNewFolder: Boolean = False): String;
 
implementation
 
uses
  Windows, Forms, shlobj;
 
var
  lg_StartFolder: String;
 
////////////////////////////////////////////////////////////////////////
// Call back function used to set the initial browse directory.
////////////////////////////////////////////////////////////////////////
function BrowseForFolderCallBack(Wnd: HWND; uMsg: UINT; lParam,
lpData: LPARAM): Integer stdcall;
begin
  if uMsg = BFFM_INITIALIZED then
    SendMessage(Wnd,BFFM_SETSELECTION, 1, Integer(@lg_StartFolder[1]));
  result := 0;
end;
 
////////////////////////////////////////////////////////////////////////
// This function allows the user to browse for a folder
//
// Arguments:-
//         browseTitle : The title to display on the browse dialog.
//       initialFolder : Optional argument. Use to specify the folder
//                       initially selected when the dialog opens.
//  mayCreateNewFolder : Flag indicating whether the user can create a
//                       new folder.
//
// Returns: The empty string if no folder was selected (i.e. if the user
//          clicked cancel), otherwise the full folder path.
////////////////////////////////////////////////////////////////////////
function BrowseForFolder(const browseTitle: String;
  const initialFolder: String ='';
  mayCreateNewFolder: Boolean = False): String;
var
  browse_info: TBrowseInfo;
  folder: array[0..MAX_PATH] of char;
  find_context: PItemIDList;
begin
  //--------------------------
  // Initialise the structure.
  //--------------------------
  FillChar(browse_info,SizeOf(browse_info),#0);
  lg_StartFolder := initialFolder;
  browse_info.pszDisplayName := @folder[0];
  browse_info.lpszTitle := PChar(browseTitle);
  Browse_info.ulFlags := BIF_USENEWUI;
  if not mayCreateNewFolder then
    browse_info.ulFlags := browse_info.ulFlags or BIF_NONEWFOLDERBUTTON;
 
  browse_info.hwndOwner := Application.Handle;
  if initialFolder <> '' then
    browse_info.lpfn := BrowseForFolderCallBack;
  find_context := SHBrowseForFolder(browse_info);
  if Assigned(find_context) then
  begin
    if SHGetPathFromIDList(find_context,folder) then
      result := folder
    else
      result := '';
    GlobalFreePtr(find_context);
  end
  else
    result := '';
end;
 
end.
Fonction d'appel simple et efficace mais c'est pas l'interface que j'aurais voulu

Alors celui-la juste un peu vieillot

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
Var
  Dir : string;
Begin
  Dir := EBureau.Text;
  if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
  EBureau.Text := Dir;
End;
Disons qu'on est en 2012 et que Windows 95/98 c finit comme même ^^

Celui-la ressemble a se que je voudrais. mais la procédure de sélectionner un fichier dans le dossier est un peu lourde pour l'utilisateur.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
interface
 
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
FileCtrl;
 
type
TDirDialog = class(TOpenDialog)
private
FIsJustExecute: boolean;
function GetDirectory: string;
procedure SetDirectory(Directory: string);
protected
procedure DoFolderChange; override;
public
constructor Create(AOwner: TComponent); override;
function Execute: Boolean; override;
published
property FileName;
property Directory: string read GetDirectory write SetDirectory;
end;
 
procedure Register;
 
implementation
 
constructor TDirDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FIsJustExecute := False;
FileName := 'Dummy.dat';
Filter := '*.*|*.*';
end;
 
procedure TDirDialog.DoFolderChange;
begin
inherited DoFolderChange;
 
if FIsJustExecute then
begin
FIsJustExecute := False;
ShowWindow(GetDlgItem(GetParent(Handle),1136),SW_HIDE);
ShowWindow(GetDlgItem(GetParent(Handle),1152),SW_HIDE);
 
SetDlgItemText(GetParent(Handle),1089,'');
SetDlgItemText(GetParent(Handle),1090,'');
SetDlgItemText(GetParent(Handle),1091,'Répertoire :');
SetDlgItemText(GetParent(Handle),1,'OK');
end;
end;
 
function TDirDialog.Execute: Boolean;
begin
FIsJustExecute := True;
if Title='' then Title := 'Sélectionnez un répertoire';
Result := inherited Execute;
end;
 
function TDirDialog.GetDirectory: string;
begin
if FileName<>'' then
if ExtractFileName(FileName)='Dummy.dat' then
Result:=ExtractFileDir(FileName)
else
Result:=FileName
else
Result:='';
end;
 
procedure TDirDialog.SetDirectory(Directory: string);
begin
FileName := IncludeTrailingBackslash(Directory) + 'Dummy.dat';
end;
 
procedure Register;
begin
RegisterComponents('Dialogues', [TDirDialog]);
end;
 
end.


voila une image de se que je voudrais exactement comme fenetre