Recent

Author Topic: [SOLVED] searching for the Icons used by function dialogs.MessageDlg  (Read 556 times)

Hartmut

  • Hero Member
  • *****
  • Posts: 613
I want to use some of the Icons, which can be displayed by function dialogs.MessageDlg(), in my own dialogs, but I cannot find them. Are they part of the Lazarus installation (on Windows or Linux) or are they only part of the Operation System?

Please can someone point me to the location, where I can find the files with this Icons?
I use Lazarus 2.0.10 and I have Windows 7 and 10 (and XP ;-) and Ubuntu 18.04.
Thanks in advance.
« Last Edit: November 18, 2022, 03:58:29 pm by Hartmut »

winni

  • Hero Member
  • *****
  • Posts: 3193
Re: searching for the Icons used by function dialogs.MessageDlg
« Reply #1 on: November 16, 2022, 06:27:10 pm »
Hi!

Have a look at lazarus/images and the subdirectories.

Winni

wp

  • Hero Member
  • *****
  • Posts: 10483
Re: searching for the Icons used by function dialogs.MessageDlg
« Reply #2 on: November 16, 2022, 07:06:11 pm »
In unit Dialogs you find a function GetDialogIcon(ID) which returns the icon for the specified ID where ID is either idDialogWarning, idDialogError, idDialogInfo, idDialogConfirm or idDialogShield as declared in unit LCLType:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   img: TCustomBitmap;
  4. begin
  5.   img := GetDialogIcon(idDialogError);   // or idDialogWarning, idDialogInfo, idDialogConfirm, idDialogShield
  6.   try
  7.     Image1.Picture.Assign(img);
  8.   finally
  9.     img.Free;
  10.   end;
  11. end;

Note, however, that for better high-dpi support, this part of the LCL recently has been reworked by Ondrej who marked this function as deprecated now. There is a new unit, DialogRes, with an auto-generated ImageList named "DialogGlyphs" in which the method "DialogIcon[ID]" returns the image index of some specific ID. And note also, that the TImage has been extended to support an Images imagelist and an ImageLindex. Therefore, the above code should be replaced in the future (in Laz 2.3.+) by

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. begin
  3.   Image1.Images := DialogGlyphs;
  4.   Image1.ImageIndex := DialogGlyphs.DialogIcon[idDialogError];
  5. end;

Hartmut

  • Hero Member
  • *****
  • Posts: 613
Re: searching for the Icons used by function dialogs.MessageDlg
« Reply #3 on: November 17, 2022, 01:27:25 pm »
Thank you winni for that info. In folder lazarus/images/states/ I found some Icons which are not the original ones, but usable.

Hello wp again. Thank you very much for that suggestion and demo. With it I could easily load the original Icons from Windows and Linux. I saved them by adding
   Image1.Picture.SaveToFile('filename.png');
because I want to use them via a resource file.

There is only one disadvantage: while the Icons saved in Linux are transparent, the Icons saved in Windows are not. When I display them, they have an ugly black background. I tried to avoid that by adding
   Image1.Transparent:=true;
before the save-command, but this did not help.

I'm a beginner to Graphics. Is it possible to save the Windows Icons with a transparent background?

wp

  • Hero Member
  • *****
  • Posts: 10483
Re: searching for the Icons used by function dialogs.MessageDlg
« Reply #4 on: November 17, 2022, 02:59:28 pm »
Current release (deprecated):
Code: Pascal  [Select][+][-]
  1. uses LCLType;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. var
  5.   img: TCustomBitmap;
  6.   png: TCustomBitmap;
  7. begin
  8.   img := GetDialogIcon(idDialogError);
  9.   try
  10.     png := TPortableNetworkGraphic.Create;
  11.     try
  12.       png.Assign(img);
  13.       png.SaveToFile('idDialogError.png');
  14.     finally
  15.       png.Free;
  16.     end;
  17.   finally
  18.     img.Free;
  19.   end;
  20. end;

Laz/main + future releases:
Code: Pascal  [Select][+][-]
  1. uses DialogRes;
  2.  
  3. procedure TForm1.Button2Click(Sender: TObject);
  4. var
  5.   png: TPortableNetworkGraphic;
  6.   idx: Integer;
  7. begin
  8.   png := TPortableNetworkGraphic.Create;
  9.   try
  10.     idx := DialogGlyphs.DialogIcon[idDialogError];
  11.     DialogGlyphs.GetBitmap(idx, png);
  12.     png.SaveToFile('idDialogError_new.png');
  13.   finally
  14.     png.Free;
  15.   end;
  16. end;

Ally

  • New Member
  • *
  • Posts: 46
Re: searching for the Icons used by function dialogs.MessageDlg
« Reply #5 on: November 17, 2022, 03:00:47 pm »
Hello Hartmut,

in one of the next Lazarus versions the enclosed icons will be included for this purpose.
Maybe they are suitable for your application.

Also in one of the next versions will be a whole icon collection.
Currently you can download them at https://gitlab.com/freepascal.org/lazarus/lazarus/-/archive/main/lazarus-main.zip?path=images/general_purpose.

Greetings Roland

Hartmut

  • Hero Member
  • *****
  • Posts: 613
Re: searching for the Icons used by function dialogs.MessageDlg
« Reply #6 on: November 17, 2022, 04:30:12 pm »
Thanks a lot to Ally for your reply and that you attached the dialog-icons (which seem not to be included in the link you provided). They look partly similar to the Icons I have in <install_dir>/lazarus/images/states/ of my Lazarus 2.0.10 installation.

Thank you very much wp for your new demo. I tried the 1st one (for current release) with Lazarus 2.0.10 / FPC 3.2.0 on Windows 7 and (an older) Windows 10, but unfortunately the Icon-files are again not transparent (they are binary identically to the ones i created with my code from reply #3).

Maybe you have another idea to get the stored Icon-files transparent?

Ally

  • New Member
  • *
  • Posts: 46
Re: searching for the Icons used by function dialogs.MessageDlg
« Reply #7 on: November 18, 2022, 10:59:55 am »
Hello Hartmut,

Quote
They look partly similar to the Icons I have in <install_dir>/lazarus/images/states/ of my Lazarus 2.0.10 installation.

Yes, but these icons are available in the sizes 16x16, 24x24, and 32x32.
If you don't want your program to be high-DPI (https://wiki.freepascal.org/High_DPI), then you can just use a 32x32 icon for your dialog (or any other size).
For a High-DPI application there should typically be three icon sizes. For dialog windows, Windows uses 32x32 icons at the default resolution of 96 DPI.
So you still need a 48x48 and a 64x64 icon. As said, only if the application should be High-DPI capable.
However, applications that are not High-DPI capable, on higher resolution screens, usually lead to an unsatisfactory result.

Greetings Roland

wp

  • Hero Member
  • *****
  • Posts: 10483
Re: searching for the Icons used by function dialogs.MessageDlg
« Reply #8 on: November 18, 2022, 11:36:28 am »
I tried the 1st one (for current release) with Lazarus 2.0.10 / FPC 3.2.0 on Windows 7 and (an older) Windows 10, but unfortunately the Icon-files are again not transparent (they are binary identically to the ones i created with my code from reply #3).

Maybe you have another idea to get the stored Icon-files transparent?
It works on Laz/main, but fails like you report already in Laz 2.2.4...

Try this instead:
Code: Pascal  [Select][+][-]
  1. uses
  2.   IntfGraphics, FPImage;
  3.  
  4. procedure TForm1.Button2Click(Sender: TObject);
  5. var
  6.   img: TCustomBitmap;
  7.   bmp: TBitmap;
  8.   intfimg: TLazIntfImage;
  9.   col: TFPColor;
  10.   x, y: Integer;
  11. begin
  12.   img := GetDialogIcon(idDialogError);   // or idDialogWarning, idDialogInfo, idDialogConfirm, idDialogShield
  13.   try
  14.     // Image1.Picture.Assign(img);  // just for testing
  15.     intfImg := img.CreateIntfImage;
  16.     try
  17.       for y := 0 to intfImg.Height-1 do
  18.         for x := 0 to intfImg.Width-1 do
  19.         begin
  20.           col := intfImg.Colors[x, y];
  21.           col.Alpha := 65535;
  22.           intfImg.Colors[x, y] := col;
  23.         end;
  24.       bmp := TBitmap.Create;
  25.       bmp.LoadFromIntfImage(intfImg);
  26.       bmp.SaveToFile('image.bmp');
  27.       // Image2.Picture.LoadFromFile('image.bmp');  // just for testing
  28.     finally
  29.       bmp.Free;
  30.     end;
  31.   finally
  32.     img.Free;
  33.   end;
  34. end;

Hartmut

  • Hero Member
  • *****
  • Posts: 613
Re: searching for the Icons used by function dialogs.MessageDlg
« Reply #9 on: November 18, 2022, 03:58:04 pm »
Thanks again to Ally for that infos. I will keep this in mind.

Thanks a lot again to wp for that new demo - it works perfectly with my Lazarus 2.0.10 / FPC 3.2.0.
To have the result files also as *.png I added the following lines:

Code: Pascal  [Select][+][-]
  1.    var PNG: TCustomBitmap;
  2.    ...
  3.    PNG:=TPortableNetworkGraphic.Create;
  4.    PNG.LoadFromIntfImage(intfImg);
  5.    PNG.SaveToFile('filename.png');
  6.    PNG.Free;

Now all saved files have transparent icons. Again I am impressed how wide your knowledge is.

 

TinyPortal © 2005-2018