I'm trying to modify the Delphi 7 Dialogs.pas to access the newer Windows 7 Open/Save dialog boxes (see Creating Windows Vista Ready Applications with Delphi). I can display the dialogs using the suggested modifications; however, events such as OnFolderChange and OnCanClose no longer function.
This appears to be related to changing the Flags:= OFN_ENABLEHOOK to Flags:=0. When Flags is set to 0 the TOpenDialog.Wndproc is bypassed and the appropriate CDN_xxxxxxx messages are not trapped.
Can anyone suggest further code modifications to the D7 Dialogs.pas that will both display the newer common dialogs and maintain the event features of the original controls?
Thanks...
You should use the IFileDialog Interface and call its
Advise()
method with an implementation of the IFileDialogEvents Interface. The Delphi 7 Windows header units won't contain the necessary declarations, so they must be copied (and translated) from the SDK header files (or maybe there's already another header translation available?), but apart from that additional effort there shouldn't be any problem to call this from Delphi 7 (or even earlier Delphi versions).Edit:
OK, since you didn't react in any way to the answers I'll add some more information. A C sample on how to use the interfaces can be had here. It's easy to translate it to Delphi code, provided you have the necessary import units.
I threw together a small sample in Delphi 4. For simplicity I created a
TOpenDialog
descendant (you would probably modify the original class) and implemented theIFileDialogEvents
directly on it:If you run this on Windows 7 it will show the new dialog and accept only files with the
txt
extension. This is hard-coded and needs to be implemented by going through theOnClose
event of the dialog. There's lots more to be done, but the provided code should suffice as a starting point.