File Open Dialog with Encodings combobox under Vista - delphi

I currently use the TOpenTextFileDialog as it has the Encodings option, but under Vista it appears using the older open dialog style. I'd like the new style open dialog, but with an encoding combobox that I can fill with custom strings. Basically I want the exact open dialog that Notepad shows under Vista. Of course I also need the corresponding save dialog as well.
I've done some research and it seems that the OFN_ENABLETEMPLATE flag causes the Vista common dialog to fall back to the old style. Unfortunately that's also the flag that lets the TOpenTextFileDialog modify the window to add the encodings combobox (if I understand things properly.)
Does anyone have a suggestion on how to get what I want under Vista but still have it work under XP? I assume that Windows 7 will have the same issue. I'm using D2009. Thanks for any suggestions or help!

With Vista a new way of dealing with file dialogs has been introduced, for more information google for the IFileDialog interface or have a look at this blog post. As you say yourself, using the OFN_ENABLETEMPLATE flag causes the Vista common dialog to fall back to the old style.
With Delphi 2007 and 2009 you can use the TFileOpenDialog and TFileSaveDialog in the Vista Dialogs components category. To make your application compatible with pre-Vista Windows versions you should keep using the TOpenTextFileDialog for those, and check at runtime whether you are on Vista and can use the new dialogs:
if Win32MajorVersion >= 6 then begin
// use TFileOpenDialog
// ...
end else begin
// use TOpenTextFileDialog
// ...
end;
Now you only need to add the customization to the Vista dialog. The blog post shows how to do this, by adding a handler for OnExecute of the dialog (because at the time when this is called the IFileDialog interface has been set up already), querying the Dialog member of the file dialog for the IFileDialogCustomize interface, and using this to add the additional controls.

Related

Why does DragAcceptFiles not work on the TEdit controls of the Tool Properties dialog in Delphi >=2005?

I am trying to make the TEdit control for the program on the "Tool Properties" dialog in the Delphi IDE (*1) accept dropping files from the explorer. This works fine in Delphi 6 and 7 but no longer works in the "new" IDE of Delphi 2005 up.
In Delphi 6/7 dropping a file on the edit control triggers a WM_DROPFILES message which a hook to the WindowProc of the TEdit can catch. In the later versions, no message is received. The hook on WindowProc still works, as it receives all kinds of other messages.
The dialog layout, names and controls is unchanged as far as I can determine.
As a test I even added my own TEdit and TComboBox to the dialog to make sure it's not a problem of these specific existing controls. They are shown fine, but dropping a file doesn't work with these either.
What else could be the problem?
(*1: the one you get through Tools -> Configure Tools -> Add or Edit
This will be a new functionality in GExperts. Auto complete already works for these controls.)
The code is here:
http://sourceforge.net/p/gexperts/code/HEAD/tree/trunk/Source/IDE/GX_IdeToolPropertiesEnhancer.pas
and the actual hooking code is here:
http://sourceforge.net/p/gexperts/code/HEAD/tree/trunk/Source/Utils/GX_dzVclUtils.pas

How to easy replace MessageDlg with Vista dialog, Delphi 7

Delphi7 (cannot use latest). I want to replace (easy way, not making my form) MessageDlg calls with Vista style dialogs (must still work on old OS!). I need buttons Yes/No/YesToAll/NoToAll in this.
How to do it?
MessageBox isn't a way: I need all 4 buttons Yes/No/YesToAll/NoToAll in one form, or maybe checkbox instead of ToAll btns.
On Vista you use the native task dialog, TaskDialogIndirect. This has all the functionality you need. You'll need to translate the headers to Pascal, but if you don't fancy doing that yourself then you can use the JEDI header translations, for instance.
On XP and older there is no task dialog. There is no native system dialog with the functionality that you desire. Therefore you need to implement the dialog yourself. Create a Delphi TForm descendent. Add the necessary text, buttons, styling etc. Show it with ShowModal.
One of the issues with all this is that TaskDialogIndirect must be bound at runtime with GetProcAddress. In fact, use GetProcAddress to determine whether TaskDialogIndirect is available, and if not fall back to the XP code path.
If you don't want to build this yourself you can use one of the many extant libraries that offer such functionality. For instance: http://blog.synopse.info/post/2011/03/05/Open-Source-SynTaskDialog-unit-for-XP,Vista,Seven

Does the frShowHelp Work Anymore for Common Dialogs in Delphi?

I was trying to add a Help button onto my Open, Save, Find and Print common dialogs in Delphi 2009.
I thought the proper way to do it was to set frShowHelp to true in the Options property of the dialog:
But when I do, the dialog comes up the same as without the option, e.g.:
I'm expecting to see a Help button below the Cancel button, but it's not there.
I'm developing under Windows Vista. Did Microsoft eliminate the capability of adding the Help button to their common dialogs, or am I doing something wrong?
Find dialog
Include frShowHelp in Options and the help button will appear. It's very hard to understand why that would not be working for you.
Print dialog
Include poHelp in Options and the help button will appear.
File dialogs
Now these did change when Vista was introduced. The new dialogs do not have, built-in, the capability to show a help button.
You can always revert to the legacy XP dialogs by setting Dialogs.UseLatestCommonDialogs to False. If you do that you can set ofShowHelp, HelpContext etc.
You should prefer to use the new dialogs if they available though. For those dialogs you need to use IFileDialogCustomize to add a help button.
In Delphi, for Vista and up, you would need to use TFileOpenDialog or TFileSaveDialog directly rather than TOpenDialog and TSaveDialog. You would create the dialog object and then request the IFileDialogCustomize interface from the Dialog property. The best place to do this is in the DoExecute event of the dialog control.
procedure TForm1.FileOpenDialog1Execute(Sender: TObject);
var
FileDialogCustomize: IFileDialogCustomize;
begin
FileDialogCustomize := FileOpenDialog1.Dialog as IFileDialogCustomize;
FileDialogCustomize.AddPushButton(0, 'Help');
end;

Delphi: Win7 side effect with forms

Win7/x64, Delphi 6 Prof.
Win7 drives me crazy with his side effect. I describe it:
When I force the suggestion with Ctrl+Space, or Delphi do this automatically, the Delphi don't show the suggestion dropdown listbox, he is only bring my all opened forms to front, one by one.
This causes that what I typing is not going to editor window: it is going to any property of the active form, of the active control.
For example.
Ctrl+Space+"ShowMes..."
I don't got ShowMessage with suggestion listbox, I type ShowMess into my main form's caption.
Many times I need to make update pack's because the buttons, caption, etc got "ShowMes" or "Excep" or other property, because I type into these windows...
This function is sometimes broken on win7.
May I can restore the normal working mode without "bring all opened form to front"?
Thanks:
dd
You can disable UAC in Windows 7, see here:
http://www.petri.co.il/disable-uac-in-windows-7.htm
Also running Delphi 6 in Windows XP compatibility mode should do the trick.
See this discussion on the embarcadero forums, it's about Delphi 7, but it's the same issue:
https://forums.codegear.com/thread.jspa?messageID=204928&tstart=0
Finally see here how to run a program in XP compatibility mode:
See: http://www.w7forums.com/application-compatibility-mode-t314.html
Or: http://www.sevenforums.com/tutorials/316-compatibility-mode.html

What is the difference between the new TFileOpenDialog and the old TOpenDialog?

What is the difference between the new TFileOpenDialog and the old TOpenDialog?
In my computer (Win 7/DXE), when I run the code, the dialogs look the same.
TOpenDialog executes TFileOpenDialog when the following conditions are met:
the program is running under Vista (and up)
UseLatestCommonDialogs is true (which is the default)
no OnIncludeItem, OnClose or OnShow events are set
So while still using TOpenDialog on your system you may likely end up automagically executing TFileOpenDialog in most cases, which explains why they are looking the same for you.
Remark: TFileOpenDialog does not fall back on older Windows systems (XP and under) - it just raises an exception. On the opposite, TOpenDialog does some sort of "fall forward".
TOpenDialog wraps the traditional GetOpenFileName. It works on all versions of Windows.
TFileOpenDialog wraps the new COM based dialog that was introduced in Vista. It therefore only works on Vista or later. It has more functionality than the older dialogs, most notably the tight integration with search.
Vista common dialog
Compatibility common dialog
The GetOpenFileName API will in fact produce the new dialogs in most situations, if called correctly, so you can't actually tell the difference. That said, historically the VCL's wrapper for GetOpenFileName was implemented imprecisely and always resulted in the compatibility dialog being shown.
But what does the new COM dialog have to offer then?
The new dialog offers a much easier customisation interface at the loss of some generality. If you use the old dialog template based customisation with GetOpenFileName on Vista or later then the dialogs degrade to ugly compatibility versions that lack functionality.
The other big advantage of the new dialogs is the ability to select unlimited number of files. The old GetOpenFileName interface returned multi-select filenames in a fixed size buffer. This can be a real limitation and in my own code I have had to hack the VCL code to make this buffer larger for when my app runs on XP.
TOpenDialog will delegate the work to TFileOpenDialog if possible. The test it uses requires all of the following to be true:
Running on Windows Vista or later.
Dialogs.UseLatestCommonDialogs global boolean variable is true (default is true). This allows you to disable the use of the new COM dialog should you elect to do so.
No dialog template is specified.
OnIncludeItem, OnClose and OnShow events are all not assigned. Presumably these cannot be fired by TFileOpenDialog.
Summary
If you continue to use TOpenDialog then you will reap the benefit of unlimited number of file in multi-select mode. However, if you wish to customise the dialog, and have the new dialogs rather than the ugly compatibilty dialogs, then you need to do the following:
On XP use TOpenDialog and the dialog template method.
On Vista and later use TFileOpenDialog and implement customisation with IFileDialogCustomize.

Resources