Jump to content
Silver Black

Enhanced messageboxes

Recommended Posts

From the glorious Windows Vista, a new kind of MessageBoxes were introduced, with an added description (beside the usual message, title, icon and buttons for user interactions).

I used this messagebox style in my Delphi projects thanks to a wrapper for the APIs featured from Vista and above, but now, from Delphi 10.3, with themes activated, I have a strange behavior: if the more than a button is not provided in the style parameter, I have a an empty title! If I disable themes the title is correctly displayed.

 

MsgBoxOK.png.591cfedfcc5f34d02b8b09e3437cea36.png23319846_MsgBoxnotitle.png.7f909e0b8964a5ba2ce237be831c8c97.png

 

Now I was thinking of doing my own custom messagebox (just a simple customized modal form), so I can even expand its functionalities. But before I reinvent the wheel, I wonder: what do you use for your apps as messageboxes? Please don't tell me "ShowMessage"! 😁

Share this post


Link to post
7 minutes ago, David Heffernan said:

Isn't this a VCL styles bug? Won't happen with plain windows theme. 

Yes, exactly.

I'm trying the TTaskDialog component, may this be the way to go? The only draw back is that I don't like a component on an actual form to make this, example if I have to show a message from a unit or project with no forms.

 

 

Edited by Silver Black

Share this post


Link to post
11 hours ago, Silver Black said:

I'm trying the TTaskDialog component

I use this a lot and it works well for a variety of use cases.

11 hours ago, Silver Black said:

I don't like a component on an actual form

You can create the component in code pretty easily. GExperts has a nifty tool to do this for you.

11 hours ago, Silver Black said:

example if I have to show a message from a unit or project with no forms

The TTaskDialog component can be placed on a data module; it can also be called from another unit (or form or data module) to keep your form clean.

Share this post


Link to post
Guest
6 hours ago, David Heffernan said:

I have my own functions that call the task dialog api rather than using the VCL component. 

Oh, that is a very helpful comment! Do you have any code to show?

Share this post


Link to post
Guest

you can try this and not need use none component in your app

unit uMyTaskDialogHelper;

interface

uses
  System.UITypes,
  System.SysUtils,
  Vcl.Dialogs;

type
  TMyTaskDialogHelper = class helper for TTaskDialog
    // your definitions...
    function MyShow(ATitle: string; ACaption: string; AText: string; AButtons: TTaskDialogCommonButtons): TModalResult;
  end;

var  // global access
  TaskDialogX: TTaskDialog;

implementation

{ TMyTaskDialogHelper }

function TMyTaskDialogHelper.MyShow(ATitle: string; ACaption: string; AText: string; AButtons: TTaskDialogCommonButtons): TModalResult;
begin
  // TaskDialogX.Buttons.Clear;
  TaskDialogX.CommonButtons := AButtons;
  //
  TaskDialogX.Title   := ATitle;
  TaskDialogX.Caption := ACaption;
  TaskDialogX.Text    := AText;
  // other defintions if you want
  //
  TaskDialogX.Execute;
  result := TaskDialogX.ModalResult;
end;

initialization // executed on app-run and global usage - of course, you use another approach

TaskDialogX := TTaskDialog.Create(nil);

finalization

TaskDialogX.Free;

end.
... you use it in Any Unit

implementation

{$R *.dfm}

uses
  uMyTaskDialogHelper;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if TaskDialogX.MyShow('My title', 'My caption', 'My text', [tcbOk, tcbCancel]) = tcbOk then ...
end;

 

Edited by Guest

Share this post


Link to post
1 hour ago, joaodanet2018 said:

you can try this and not need use none component in your app


... you use it in Any Unit

implementation

{$R *.dfm}

uses
  uMyTaskDialogHelper;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if TaskDialogX.MyShow('My title', 'My caption', 'My text', [tcbOk, tcbCancel]) = 1 then ...
end;

 

TY so much, that's what I need! ❤️

Share this post


Link to post
2 hours ago, Dany Marmur said:

Oh, that is a very helpful comment! Do you have any code to show?

No. You just read the Win32 docs and off you go. 

  • Haha 1

Share this post


Link to post

Eventually I end up using this simply code, that is very straight forward, using a component created on the go that handles the taskdialog for every different Windows version hassle-free and suppports thems (and no need to use API). 

 

procedure TFromMain.Button1Click(Sender: TObject);
begin
  with TTaskDialog.Create(nil) do begin
    try
      Caption       := 'Dialog Caption';
      Title         := 'Dialog Title';
      Text          := 'This is dialog text.';
      CommonButtons := [tcbClose];
      Execute;
    finally
      Free;
    end;
  end;
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×