1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| function MessageDialogChecked(Const Msg, ChkMsg : string; var CheckedValue : boolean; DlgType : TMsgDlgType; Buttons : TMsgDlgButtons) : Word;
procedure PlacerTypeBouton(OldBtn : TButton; NewBtn : TBitBtn; LeType : TBitBtnKind; BtnType: TMsgDlgBtn);
begin
{ 1 : Met le type de bouton et le modalresult }
NewBtn.Kind := LeType;
NewBtn.ModalResult := OldBtn.ModalResult;
if (NewBtn.Default) then NewBtn.TabOrder := 0;
{ 1 }
{ 2 : Le bouton d'annulation (si) présent n'est plus le vieux mais le nouveau }
if (OldBtn.Cancel) then
begin
OldBtn.Cancel := False;
NewBtn.Cancel := True;
end;
{ 2 }
{ 3 : Au cas où le OnClick soit redéfini }
if Assigned(OldBtn.OnClick) then
NewBtn.OnClick := OldBtn.OnClick;
{ 3 }
end;
var Frm : TForm;
Chk : TCheckBox;
StMsg : string;
i : integer;
OldButton : TButton;
NewButton : TBitBtn;
begin
stMsg := Msg + StringOfChar(Chr(13),2);
Frm := CreateMessageDialog(Msg,DlgType,Buttons);
Frm.Height := Frm.Height + 10;
try
// Création de la case à cocher
Chk := TCheckBox.Create(Frm);
Chk.Checked := CheckedValue; // Valeur par défaut
Chk.Caption := chkMsg; // Message derrière la checkbox
Chk.Left := 12; // Position Y de la case
Chk.Top := Frm.Height - Chk.Height - 70; // Position X de la case
Chk.Width := Frm.Width - 11; // Taille de la case
Chk.Visible := True;
Chk.Parent := Frm;
// Postionnement au centre l'écran
with Frm do
begin
Position := poScreenCenter;
for i := 0 to ControlCount - 1 do
begin
if (Controls[i] is TButton) then
begin
OldButton := TButton(Controls[i]);
{ Créé et place le nouveau bouton }
NewButton := TBitBtn.Create(Frm);
NewButton.Top := OldButton.Top + 12;
NewButton.Left := OldButton.Left;
NewButton.Width := OldButton.Width;
NewButton.Height := OldButton.Height + 2; // <= Place pour le glyphe
NewButton.Parent := OldButton.Parent;
case OldButton.ModalResult of
mrOK : PlacerTypeBouton(OldButton, NewButton, bkOK, mbOK);
mrCancel : PlacerTypeBouton(OldButton, NewButton, bkCancel, mbCancel);
mrAbort : PlacerTypeBouton(OldButton, NewButton, bkAbort, mbAbort);
mrRetry : PlacerTypeBouton(OldButton, NewButton, bkRetry, mbRetry);
mrIgnore : PlacerTypeBouton(OldButton, NewButton, bkIgnore, mbIgnore);
mrYes : PlacerTypeBouton(OldButton, NewButton, bkYes, mbYes);
mrNo : PlacerTypeBouton(OldButton, NewButton, bkNo, mbNo);
mrAll : PlacerTypeBouton(OldButton, NewButton, bkAll, mbAll);
mrYesToAll : PlacerTypeBouton(OldButton, NewButton, bkYes, mbYesToAll);
mrNoToAll : PlacerTypeBouton(OldButton, NewButton, bkNo, mbNoToAll);
else
PlacerTypeBouton(OldButton, NewButton, bkOK, mbOK);
end;
{ Désactive et masque l'autre bouton }
OldButton.Enabled := False;
OldButton.Visible := False;
end;
end;
end;
// Valeur de résultat
Result := Frm.ShowModal;
CheckedValue := Chk.Checked;
finally
Frm.Free;
end;
end; |
Partager