Board index » delphi » Options in Messageboxes (or system dialogs).

Options in Messageboxes (or system dialogs).

Hello,

I know I've seen the hint for this topic before, but I can't seem to locate
it.  I have used MESSAGEDLG extensively throughout my app.  Now I find I
would like to give the user the option to turn this dialogs off after they
appear once.  The natural way (it seems) to do this is to have a message
dialog that has a checkbox saying something to the effect "Don't show me
this anymore".  I've seen this in numerous windows apps, and it seems to me
this is part of the windows common dialogs.  Any ideas on how I implement
this type of windows dialog.

Thanks,

David

 

Re:Options in Messageboxes (or system dialogs).


Quote
In article <8q5g1i$1j...@bornews.borland.com>, David K wrote:
> I know I've seen the hint for this topic before, but I can't seem to locate
> it.  I have used MESSAGEDLG extensively throughout my app.  Now I find I
> would like to give the user the option to turn this dialogs off after they
> appear once.  The natural way (it seems) to do this is to have a message
> dialog that has a checkbox saying something to the effect "Don't show me
> this anymore".  I've seen this in numerous windows apps, and it seems to me
> this is part of the windows common dialogs.  Any ideas on how I implement
> this type of windows dialog.

Make your own messagedlg function. You don't need to start completely from
scratch, there is a function CreateMessageDialog in dialogs.pas that will
create the standard message form, but not show it. You can then add a
checkbox to the form (in code) and grow the form vertically to make room for
it. Then you ShowModal it. As far as i know there is no common dialog for
this purpose (and MessageDlg is a pure VCL dialog anyway, not a Windows
dialog).

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:Options in Messageboxes (or system dialogs).


Quote
>In article <8q5g1i$1j...@bornews.borland.com>, David K wrote:
>> I know I've seen the hint for this topic before, but I can't seem to
locate
>> it.  I have used MESSAGEDLG extensively throughout my app.  Now I find I
>> would like to give the user the option to turn this dialogs off after
they
>> appear once.  The natural way (it seems) to do this is to have a message
>> dialog that has a checkbox saying something to the effect "Don't show me
>> this anymore".  I've seen this in numerous windows apps, and it seems to
me
>> this is part of the windows common dialogs.  Any ideas on how I implement
>> this type of windows dialog.

Here's a working version of a custom dialog as Peter suggested.

Gerrit Beuze
ModelMaker

unit CondMsgDlg;

interface

uses SysUtils, Classes, Controls, Forms, StdCtrls, Dialogs;

function CondMessageDlg(const Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; var Cond: Boolean; const CheckMsg: string = ''):
Integer;

implementation

function CondMessageDlg(const Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgButtons; var Cond: Boolean; const CheckMsg: string = ''):
Integer;
var
  F: TForm;
  B: TControl;
  X: Integer;
  CheckBox: TCheckBox;
  Btn: TMsgDlgBtn;
  NrAssigned: Integer;
  HackBtns: array[0..1] of TMsgDlgBtn;
const
  ButtonNames: array[TMsgDlgBtn] of string = ( // copied from dialogs
    'Yes', 'No', 'OK', 'Cancel', 'Abort', 'Retry', 'Ignore', 'All',
'NoToAll',
    'YesToAll', 'Help');
begin
  NrAssigned := 0;
  for Btn := High(TMsgDlgBtn) downto Low(TMsgDlgBtn) do
  begin
    if not (Btn in Buttons) then
    begin
      HackBtns[NrAssigned] := Btn;
      Inc(NrAssigned);
      if NrAssigned = 2 then Break;
    end;
  end;
  Assert(NrAssigned = 2);
  Include(Buttons, HackBtns[0]);
  Include(Buttons, HackBtns[1]);
  F := CreateMessageDialog(Msg, DlgType, Buttons);
  try
    // Hide OK Btn and move No Btn on top
    B := F.FindChildControl(ButtonNames[HackBtns[0]]);
    B.Visible := False;
    B := F.FindChildControl(ButtonNames[HackBtns[1]]);
    B.Visible := False;
    // now move all Btns
    Exclude(Buttons, HackBtns[0]);
    Exclude(Buttons, HackBtns[1]);
    X := F.ClientWidth;
    for Btn := High(TMsgDlgBtn) downto Low(TMsgDlgBtn) do
      if Btn in Buttons then
      begin
        B := F.FindChildControl(ButtonNames[Btn]);
        Assert(Assigned(B));
        X := X - B.Width - 8;
        B.Left := X;
      end;
    CheckBox := TCheckBox.Create(F);
    with CheckBox do
    begin
      Parent := F;
      if CheckMsg = '' then
        Caption := 'Don''t ask me again'
      else
        Caption := CheckMsg;
      Left := 8;
      if Assigned(B) then
        Top := B.Top + (B.Height - CheckBox.Height) div 2
      else
        Top := F.Height - CheckBox.Height - 4;
      Width := F.Canvas.TextWidth(Caption) + 20;
      Checked := Cond;
    end;
    Result := F.ShowModal;
    Cond := CheckBox.Checked;
  finally
    F.Free;
  end;
end;

end.

Other Threads