Prog1020
Prog1020

Reputation: 4781

Modern Win7 Open/Save dialog for Delphi 7 app

Im using Delphi7 with TNT controls. Is there a way to call modern Open/Save dialogs on Win7? Maybe a patch to VCL, patch to TNT? TNT patch is preferred as I need Unicode aware dialogs, but VCL patch may be needed (less) too.

Upvotes: 0

Views: 1169

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

Probably the easiest way is to call the API functions GetOpenFileName and GetSaveFileName directly. These will, unless you use some of the more esoteric functionality, show the modern dialogs on Vista and up.

Obviously you'll need to call the W variants, and pass the W versions of the structs.

Here's the simplest example I can construct:

var
  ofn: TOpenFilenameW;
  FileName: array [0..MAX_PATH-1] of WideChar;
begin
  FillChar(ofn, SizeOf(ofn), 0);
  ofn.lStructSize := SizeOf(ofn);
  ofn.hWndOwner := Handle;
  ofn.lpstrFilter := 'All files'#0'*.*'#0;
  FileName[0] := #0;
  ofn.lpstrFile := @FileName;
  ofn.nMaxFile := Length(FileName);
  ofn.lpstrTitle := 'Select File';
  if GetOpenFileNameW(ofn) then
    MessageBoxW(Handle, FileName, nil, MB_OK);
end;

Naturally you can expand this to have more functionality.

Upvotes: 3

Related Questions