Blog Options
Archive
<< November 2025 >>-
Wednesday 5
- Cloud Development with Backend-as-a-Service -
Monday 3
- Next Generation Data Grid for Delphi: Paging
Authors
- Bernard Roussely (3)
- Wagner Landgraf (93)
- Dennis Röhner (1)
- Roman Yankovsky (2)
- Bart Holvoet (41)
- Aaron Decramer (59)
- Pieter Scheldeman (125)
- Nancy Lescouhier (32)
- Adrian Gallero (34)
- Bruno Fierens (445)
- Marcos Douglas B. Santos (5)
- Bernard (4)
- Bradley Velghe (35)
- Andrew Simard (86)
- Holger Flick (15)
- Gjalt Vanhouwaert (42)
- Tunde Keller (32)
- Masiha Zemarai (117)
Blog
All Blog Posts | Next Post | Previous Post
The new File Open / Save dialogs in Windows Vista
Wednesday, January 21, 2009
Introduction
In Windows Vista the common File Open and File Save dialogs have got a facelift as well. Unfortunately, Microsoft didn't make the new common file dialogs 100% backwards compatible with the existing GetOpenFileName, GetSaveFileName API calls. As soon as the flag OFN_ENABLEHOOK or OFN_ENABLETEMPLATE are used, the functions fall back to their old appearance. Unfortunately, Delphi uses by default OFN_ENABLEHOOK (just to center the dialog) and optionally OFN_ENABLETEMPLATE. This means that there is not a way to use the new Windows Vista style dialogs with TOpenDialog or TSaveDialog. When TOpenDialog is used in Delphi on Windows Vista, following dialog appears:
where the new Windows Vista style dialogs look like:
So, to start using the new Windows Vista Open File & Save File dialogs today
from Delphi, either the VCL should be changed (which we suspect Borland will do
in a future Delphi version) or a replacement function can be used. We've
included here a quick replacement function for TOpenDialog and TSaveDialog that
uses the new nice Windows Vista dialogs today:
function OpenSaveFileDialog(Parent:
TWinControl; const DefExt, Filter, InitialDir, Title: string; var FileName:
string;
MustExist, OverwritePrompt, NoChangeDir, DoOpen: Boolean): Boolean;
var
ofn: TOpenFileName;
szFile: array[0..MAX_PATH] of Char;
begin
Result := False;
FillChar(ofn, SizeOf(TOpenFileName), 0);
with ofn do
begin
lStructSize := SizeOf(TOpenFileName);
hwndOwner := Parent.Handle;
lpstrFile := szFile;
nMaxFile := SizeOf(szFile);
if (Title <> '') then
lpstrTitle := PChar(Title);
if (InitialDir <> '') then
lpstrInitialDir := PChar(InitialDir);
StrPCopy(lpstrFile, FileName);
lpstrFilter := PChar(ReplaceStr(Filter, '|', #0)+#0#0);
if DefExt <> '' then
lpstrDefExt := PChar(DefExt);
end;
if MustExist then
ofn.Flags := ofn.Flags or OFN_FILEMUSTEXIST;
if OverwritePrompt then
ofn.Flags := ofn.Flags or OFN_OVERWRITEPROMPT;
if NoChangeDir then
ofn.Flags := ofn.Flags or OFN_NOCHANGEDIR;
if DoOpen then
begin
if GetOpenFileName(ofn) then
begin
Result := True;
FileName := StrPas(szFile);
end;
end
else
begin
if GetSaveFileName(ofn) then
begin
Result := True;
FileName := StrPas(szFile);
end;
end
end;
Bruno Fierens
This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post