Silver Black 23 Posted February 19, 2022 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. 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
David Heffernan 2353 Posted February 19, 2022 Isn't this a VCL styles bug? Won't happen with plain windows theme. Share this post Link to post
Silver Black 23 Posted February 19, 2022 (edited) 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 February 19, 2022 by Silver Black Share this post Link to post
David Heffernan 2353 Posted February 19, 2022 You don't need a component on a form Share this post Link to post
corneliusdavid 220 Posted February 20, 2022 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
David Heffernan 2353 Posted February 20, 2022 I have my own functions that call the task dialog api rather than using the VCL component. Share this post Link to post
Guest Posted February 20, 2022 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 Posted February 20, 2022 (edited) 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 February 20, 2022 by Guest Share this post Link to post
Silver Black 23 Posted February 20, 2022 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
David Heffernan 2353 Posted February 20, 2022 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. 1 Share this post Link to post
Silver Black 23 Posted February 20, 2022 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