unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
type
  TRound = (rtEccesso,rtDifetto,rtMath);
  TMsgDlgType = (mtAvviso, mtErrore, mtInformazione, mtConferma, mtPersonale);
  TMsgDlgBtn = (mbSi, mbNo, mbOk, mbAnnulla, mbAbbandona, mbRiprova,
                   mbIgnora, mbTutto, mbHelp);
  TMsgDlgBtns = set of TMsgDlgBtn;
implementation
{$R *.DFM}
function Max(I, J: Integer): Integer;
begin
  if I > J then Result := I else Result := J;
end;
function GetAveCharSize(Canvas: TCanvas): TPoint;
var Metrics: TTextMetric;
begin
  GetTextMetrics(Canvas.Handle, Metrics);
  Result.X:=Metrics.tmAveCharWidth;
  Result.Y:=Metrics.tmHeight;
end;
function CreateMsgDialog(const Msg: string; DlgType: TMsgDlgType;
  Buttons: TMsgDlgBtns): TForm;
const
  mcHorzMargin = 6;
  mcVertMargin = 6;
  mcHorzSpacing = 8;
  mcVertSpacing = 8;
  mcButtonWidth = 42;
  mcButtonHeight = 12;
  mcButtonSpacing = 4;
const
  Captions: array[TMsgDlgType] of string = ('Avviso','Errore',
    'Informazione','Conferma','');
  IconIDs: array[TMsgDlgType] of PChar = (IDI_EXCLAMATION, IDI_HAND,
    IDI_ASTERISK, IDI_QUESTION, nil);
  ButtonNames: array[TMsgDlgBtn] of string = (
    'Si', 'No', 'Ok', 'Annulla', 'Abbandona', 'Riprova', 'Ignora', 'Tutto', 'Help');
  ButtonCaptions: array[TMsgDlgBtn] of string = (
    '&Si', '&No', '&Ok', '&Annulla', 'A&bbandona', '&Riprova', '&Ignora','&Tutto','&Help');
  ModalResults: array[TMsgDlgBtn] of Integer = (
    mrYes, mrNo, mrOk, mrCancel, mrAbort, mrRetry, mrIgnore, mrAll, mrNone);
var
  DialogUnits: TPoint;
  HorzMargin, VertMargin, HorzSpacing, VertSpacing, ButtonWidth,
  ButtonHeight, ButtonSpacing, ButtonCount, ButtonGroupWidth,
  IconTextWidth, IconTextHeight, X: Integer;
  B, DefaultButton, CancelButton: TMsgDlgBtn;
  IconID: PChar;
  TextRect: TRect;
begin
  Result := TForm.CreateNew(Application);
  with Result do
  begin
    BorderStyle := bsToolWindow;
    BorderIcons:=[];
    Canvas.Font := Font;
    //stile della finestra
    Font.Style := [fsBold];
    Font.size:=10;
    Font.Color:= clBlue;
    DialogUnits := GetAveCharSize(Canvas);
    HorzMargin := MulDiv(mcHorzMargin, DialogUnits.X, 4);
    VertMargin := MulDiv(mcVertMargin, DialogUnits.Y, 8);
    HorzSpacing := MulDiv(mcHorzSpacing, DialogUnits.X, 4);
    VertSpacing := MulDiv(mcVertSpacing, DialogUnits.Y, 8);
    ButtonWidth := MulDiv(mcButtonWidth, DialogUnits.X, 4);
    ButtonHeight := MulDiv(mcButtonHeight, DialogUnits.Y, 8);
    ButtonSpacing := MulDiv(mcButtonSpacing, DialogUnits.X, 4);
    SetRect(TextRect, 0, 0, Screen.Width div 2, 0);
    DrawText(Canvas.Handle, PChar(Msg), -1, TextRect,
      DT_CALCRECT or DT_WORDBREAK);
    IconID := IconIDs[DlgType];
    IconTextWidth := TextRect.Right;
    IconTextHeight := TextRect.Bottom;
    if IconID <> nil then
    begin
      Inc(IconTextWidth, 32 + HorzSpacing);
      if IconTextHeight < 32 then IconTextHeight := 32;
    end;
    ButtonCount := 0;
    for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
      if B in Buttons then Inc(ButtonCount);
    ButtonGroupWidth := 0;
    if ButtonCount <> 0 then
      ButtonGroupWidth := ButtonWidth * ButtonCount +
        ButtonSpacing * (ButtonCount - 1);
    ClientWidth := Max(IconTextWidth, ButtonGroupWidth) + HorzMargin * 2;
    ClientHeight := IconTextHeight + ButtonHeight + VertSpacing +
      VertMargin * 2;
    Left := (Screen.Width div 2) - (Width div 2);
    Top := (Screen.Height div 2) - (Height div 2);
    if DlgType =mtPersonale
    then Caption:=Application.name
    else Caption := Captions[DlgType];
    if IconID <> nil then
      with TImage.Create(Result) do
      begin
        Name := 'Image';
        Parent := Result;
        Picture.Icon.Handle := LoadIcon(0, IconID);
        SetBounds(HorzMargin, VertMargin, 32, 32);
      end;
    with TLabel.Create(Result) do
    begin
      Name := 'Message';
      Parent := Result;
      WordWrap := True;
      Caption := Msg;
      BoundsRect := TextRect;
      SetBounds(IconTextWidth - TextRect.Right + HorzMargin, VertMargin,
        TextRect.Right, TextRect.Bottom);
    end;
    if mbOk in Buttons then DefaultButton := mbOk else
    if mbSi in Buttons then DefaultButton := mbSi else
    DefaultButton := mbRiprova;
    if mbAnnulla in Buttons then CancelButton := mbAnnulla;
    X := (ClientWidth - ButtonGroupWidth) div 2;
    for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
      if B in Buttons then
        with TButton.Create(Result) do
        begin
          Name := ButtonNames[B];
          //stile dei bottoni
          Parent := Result;
          ParentFont:=true;
          Font.Style:=[fsBold];
          Font.Size:=10;
          Caption := ButtonCaptions[B];
          ModalResult := ModalResults[B];
          if B = DefaultButton then Default := True;
          if B = CancelButton then Cancel := True;
          SetBounds(X, IconTextHeight + VertMargin + VertSpacing,
            ButtonWidth, ButtonHeight);
          Inc(X, ButtonWidth + ButtonSpacing);
        end;
  end;
end;
function EfMsg(const Msg: string;
                     DlgType: TMsgDlgType;
                     Buttons: TMsgDlgBtns): Integer;
begin
  with CreateMsgDialog(Msg, DlgType, Buttons) do
    try
      Result := ShowModal;
    finally
      Free;
    end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
    EfMsg('Daniele',mtErrore,[mbOk]);
end;
end.