Recent

Author Topic: Dialog ShowModal and an icon within caption bar?  (Read 1093 times)

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Dialog ShowModal and an icon within caption bar?
« on: March 27, 2024, 09:59:16 am »
I sometimes already had noticed, but yet never really paid attention to:

Windows 10 64bit, Lazarus 3.2
A subform with BorderStyle bsDialog, opened with ShowModal, normally doesn’t have an icon within the caption bar.
But sometimes it has … and I would like to keep this / to have it as a useable feature, to be used by intention, rather than to be seen as a bug ….

But when does the icon do appear? If eg. a TDateTimePicker within the dialog is opened.
Looks like as if BorderIcons := [biSystemMenu], if set, would have come into effect just now, but not at dialog’s start.

Edit:
Maybe it’s better to express it vice versa:
if BorderIcons := [biSystemMenu] can be defined, then SystemMenu / Icon should be visible from the beginning. – Or is it by design that it does not?

« Last Edit: March 27, 2024, 10:30:47 am by d7_2_laz »
Lazarus 3.2  FPC 3.2.2 Win10 64bit

ASerge

  • Hero Member
  • *****
  • Posts: 2262
Re: Dialog ShowModal and an icon within caption bar?
« Reply #1 on: March 27, 2024, 07:30:40 pm »
You can see this bug and its causes without TDateTimePicker:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   LForm: TForm;
  4.   LTimer: TTimer;
  5. begin
  6.   LForm := TForm.Create(Self);
  7.   LTimer := TTimer.Create(LForm);
  8.   LTimer.Interval := 2 * MSecsPerSec;
  9.   LTimer.OnTimer := @Timer1Timer;
  10.   LForm.Parent := Self;
  11.   LForm.Show;
  12. end;
  13.  
  14. procedure TForm1.FormCreate(Sender: TObject);
  15. begin
  16.   BorderStyle := bsDialog;
  17. end;
  18.  
  19. procedure TForm1.Timer1Timer(Sender: TObject);
  20. begin
  21.   ((Sender as TComponent).Owner as TForm).BorderStyle := bsDialog;
  22. end;

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Re: Dialog ShowModal and an icon within caption bar?
« Reply #2 on: March 27, 2024, 08:25:18 pm »
Thanks ASerge; tried  -– true. But, do one see also the causes here? Hm.
It did remind me somehow at my first rough thought when noticeing the calender thing:
looks like the system menu / icon becomes visible just at the moment when the dialog itself is no longer topmost (is slipping to background). Rather than to be specific related to a DateTimePicker of course.

Btw, reading around in web (Lazarus and Delphi) I was pretty unsure if at the end BorderStyle bsDialog and BorderIcons biSystemMenu are really foreseen to legitimately coexist. It stays a bit vague for me if they too belong to those which are “mutually exclusive”.
https://docwiki.embarcadero.com/Libraries/Sydney/en/Vcl.Forms.TCustomForm.BorderIcons

See also the old  problem report about “bsDialog Form shows Icon” as being a bug (but, why a bug??)
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/19321

I think it would be useful to clarify first whether “modal dialog” and “system menu” is a valid combination or not. Probably there might be different opinions.
Lazarus 3.2  FPC 3.2.2 Win10 64bit

ASerge

  • Hero Member
  • *****
  • Posts: 2262
Re: Dialog ShowModal and an icon within caption bar?
« Reply #3 on: March 28, 2024, 08:04:11 pm »
Thanks ASerge; tried  -– true. But, do one see also the causes here? Hm.
TDateTimePicker uses a nested form for the calendar.
The problem is that in Lazarus changes to the border style of a nested form are reflected on the parent form.
There is no such thing in Delphi.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 512
Re: Dialog ShowModal and an icon within caption bar?
« Reply #4 on: March 28, 2024, 09:51:39 pm »
ASerge ok, understood …
But let’s put this buggy side-effect for a moment besides (removing here the datetimepicker):

I’d still unsure (probably I’m the only one?) what would be the correct behaviour:
Does and should by principle a modal dialog exclude the display of an icon (resp. system menu)?
Or should it be possible to display the icon if wanted and configured (ie. by setting BorderIcons biSystemMenu)?

For the cases the latter might be wanted (may happen) I found this little workaround:

Code: Pascal  [Select][+][-]
  1.   TForm2 = class(TForm)     //  Form2 is the modal dialog here
  2.  …..
  3.   protected
  4.     procedure CreateWnd; override;
  5.  …..
  6.  
  7. procedure TForm2.CreateWnd;
  8. begin
  9.   inherited;
  10.  
  11.   // --- Assure icon display picked up from application icon:
  12.   //SendMessage(Handle, WM_SETICON, ICON_BIG,  Windows.LoadIcon(MainInstance, 'MAINICON'));
  13.  
  14.   // --- Assure icon display picked up from the form's icon handle:
  15.   Windows.SendMessage(Handle, WM_SETICON, ICON_BIG, Self.BigIconHandle);
  16.  
  17. end;
Lazarus 3.2  FPC 3.2.2 Win10 64bit

 

TinyPortal © 2005-2018