6

I'm on Delphi 10.4.

I'm looking for a way to dynamically insert a number on the app's icon on the taskbar, so the user can know about how many tasks the apps has done so far. This would be dynamically, as soon as the app does a new task, it will increase the icon's number.

Something like the image below.

Is this possible ?

I don't have any code to post here because i don't have any idea how to do this.

enter image description here

Kromster
  • 7,181
  • 7
  • 63
  • 111
delphirules
  • 6,443
  • 17
  • 59
  • 108
  • 4
    You would have to draw a new icon each time, and then assign it to the [`TForm.Icon`](http://docwiki.embarcadero.com/Libraries/en/Vcl.Forms.TForm.Icon) property. Load a base icon into a `TBitmap`, draw the number on top of it, and then `Assign()` it to the `Icon`. – Remy Lebeau Dec 29 '20 at 19:05
  • 1
    @RemyLebeau: You may do it like that, but you don't have to. The Windows taskbar supports overlay icons since Windows 7. – Andreas Rejbrand Dec 29 '20 at 20:44
  • @AndreasRejbrand yes you could do it that way, except that such overlaps are quite small (16x16) which would make reading numbers difficult especially on large displays, and you have no control over the *placement* of the overlays over the main taskbar icon. – Remy Lebeau Dec 29 '20 at 21:23
  • "No control over the placement" is a feature, because then you get the *standard* placement. Also, the taskbar button is small to begin with; you aren't supposed to put much information in it, but a single digit should work fairly well. – Andreas Rejbrand Dec 29 '20 at 21:27

1 Answers1

11

You might not be aware of the TTaskbar taskbar-configuration component and its OverlayIcon property.

Example:

Screen recording of an app with taskbar icon overlays.

with a very straightforward implementation:

procedure TForm1.btnInfoClick(Sender: TObject);
var
  io: TIcon;
begin
  io := TIcon.Create;
  try
    io.Handle := LoadIcon(0, IDI_INFORMATION);
    Taskbar1.OverlayIcon := io
  finally
    io.Free;
  end;
end;

In your case, you can either create icons 1.png, 2.png, ... non-programmatically and use those, or you can create icons programmatically (create a CreateOverlayIcon(ANumber: Integer): TIcon function).

I should warn you, however, that the TTaskbar component used to be (very) buggy. Therefore I would not use that one; instead, I would use the ITaskbarList3::SetOverlayIcon API directly.

In any case, my suggestion is to split your problem into two parts:

  1. Create overlay icons.
  2. Use the Windows 7 taskbar overlay icon feature to display these on top of your original icon.
Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • Thank you ! Problem in create overlay icons is , i'd need hundreds of icons as the number of tasks my app does can easily go up 500. – delphirules Dec 30 '20 at 11:30