How to use the standard Delphi confirmation dialog, but with the "Do not ask me again" checkbox?

In many confirmation dialogs, it is useful to have this option (a quick way to disable confirmation). But I can not find how to do it. I do not want to develop it myself, because I need this dialogue to be standard and not want to redo it with every update of Delphi. Is there an easy way to use the standard Delphi confirmation dialog with this flag?

UPDATE2. The proposed SynTaskDialog library from the Synopse project does an excellent job (all I need and more), I will use it in my projects. Thanks!

UPDATE So thanks guys for the ideas. The MessageBoxCheck system function is a nice solution, but it doesn't seem to be as stable as it should be. In general, I agree that it is recommended to use the latest API functions to provide users with the best user interface of modern OS and use the old-fashioned design for older systems. At the moment, I remain on a simple solution (the code is the following), but if someone shares the user interface support code for a modern OS, it will be fine.

function MsgDlgWithCB(const Msg,Title,CBMsg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn; var cbDontAskAnymore: TCheckBox): TForm; var i: integer; b: TButton; y: integer; begin Result := CreateMessageDialog(Msg, DlgType, Buttons, DefaultButton) ; Result.Position := poScreenCenter; cbDontAskAnymore := TCheckBox.Create(Result); cbDontAskAnymore.Caption := CBMsg; cbDontAskAnymore.Width := 130; y := -1; for i := 0 to result.ComponentCount-1 do if result.Components[i] is TButton then begin b := TButton(result.Components[i]); b.Left := b.Left + cbDontAskAnymore.Width + 16; Result.ClientWidth := Max(Result.ClientWidth, b.Left+b.Width+16); y := b.Top+b.Height-cbDontAskAnymore.Height; end; if y<0 then y := Result.ClientHeight - cbDontAskAnymore.height - 16; Result.Caption := Title; cbDontAskAnymore.Parent := Result; cbDontAskAnymore.Top := y; cbDontAskAnymore.Left := 8; end; function MessageDlgCheckbox(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn; var cbDontAskAnymore: Boolean; const Title: string ='Confirmation'; const CBMsg: string = 'Don''t ask anymore'): integer; var f: TForm; c: TCheckbox; begin f := MsgDlgWithCB(Msg,Title,CBMsg,DlgType,Buttons,DefaultButton,c); try result := f.ShowModal; cbDontAskAnymore := c.Checked; finally f.free; end; end; 
+7
delphi dialog delphi-xe3 confirmation
source share
2 answers

You can use our Open Source SynTaskDialog block .

Windows provides a common task dialog available with Vista / Seven. But with previous versions of Windows there isn’t, i.e. Windows XP or 2K.

This module (licensed under the tri-license MPL / GPL / LGPL) will use the new TaskDialog API for Vista / Seven and imitate it using pure Delphi code and standard thematic components of VCL under XP or 2K. It supports Delphi 6 to XE4 and is ready to work in Unicode Win32 / Win64.

Here is the result on a 64-bit Windows Seven computer:

enter image description here

And here is the same dialog created from our emulated pure Delphi code:

enter image description here

Since this screenshot was taken on a Win 7 machine, the style is native to this OS. When the emulated version of the dialog is launched on XP, it is displayed in a style native to this OS.

You have the checkbox "Do not request this parameter next time" and potentially much more!

+12
source share

The native system functionality that offers these features is a dialog box introduced in Vista. This gives you the ability to show much more efficient dialogs than the old MessageBox API.

If you need to support XP, you will need to create your own dialog. For example, based on TForm and a call to ShowModal. If you do this, make a form that can build itself dynamically. Do not make one form for the message you are showing!

In my code base, I have my own wrapper for the task dialog box. This detects at run time versions of Windows that do not support the task dialog and do not return to the Delphi custom dialog.

As for SHMessageBoxCheck, I would be a little afraid to depend on this. According to its documentation, it is not supported outside of XP, and you should import it in order. I personally would be concerned that it might be removed from a future version of Windows. However, MS has a lot of experience in doing everything possible to ensure that legacy applications work with new releases of the OS.

+5
source share

All Articles