Recent

Author Topic: Task Icon Progress Bar under Windows  (Read 1270 times)

kupferstecher

  • Sr. Member
  • ****
  • Posts: 297
Task Icon Progress Bar under Windows
« on: March 31, 2019, 12:57:55 pm »
Hello,

just want to share how to use the taskbar progress bar under Windows. I didn't find any Lazarus-specific description on the web, so it might be helpful for someone. Unfortunately its a Windows only solution.

See attached screenshots. The windows task icons offer the possibility to show a progress bar, this is useful for showing the progress of longer lasting actions, when the user doesn't have the application window in the foreground.

Regards~

--
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   ShlObj, comobj, Win32Int, InterfaceBase, LCLIntf;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Button2: TButton;
  18.     Button3: TButton;
  19.     Button4: TButton;
  20.     Label1: TLabel;
  21.     Label2: TLabel;
  22.     procedure Button1Click(Sender: TObject);
  23.     procedure Button2Click(Sender: TObject);
  24.     procedure Button3Click(Sender: TObject);
  25.     procedure Button4Click(Sender: TObject);
  26.     procedure FormCreate(Sender: TObject);
  27.   private
  28.       FTaskBarList: ITaskbarList3;
  29.       AppHandle: THandle;
  30.   public
  31.  
  32.   end;
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37. IMPLEMENTATION
  38.  
  39. {$R *.lfm}
  40.  
  41. { TForm1 }
  42.  
  43. procedure TForm1.Button1Click(Sender: TObject);
  44. begin
  45.   FTaskBarList.SetProgressState(AppHandle, TBPF_NOPROGRESS);
  46.  
  47.   Application.Title:= 'project1';
  48. end;
  49.  
  50. procedure TForm1.Button2Click(Sender: TObject);
  51. begin
  52.   FTaskBarList.SetProgressState(AppHandle, TBPF_Normal);
  53.   FTaskBarList.SetProgressValue(AppHandle, 40, 100);
  54.  
  55.   Application.Title:= 'progress';
  56. end;
  57.  
  58. procedure TForm1.Button3Click(Sender: TObject);
  59. begin
  60.   FTaskBarList.SetProgressState(AppHandle, TBPF_Error);
  61.   FTaskBarList.SetProgressValue(AppHandle, 50, 100);
  62.  
  63.   Application.Title:= 'error';
  64. end;
  65.  
  66. procedure TForm1.Button4Click(Sender: TObject);
  67. begin
  68.   sleep(2000);
  69.   LCLIntf.SetForegroundWindow(AppHandle);
  70.  
  71. end;
  72.  
  73. procedure TForm1.FormCreate(Sender: TObject);
  74. begin
  75.   AppHandle := TWin32WidgetSet(WidgetSet).AppHandle;
  76.   FTaskBarList := CreateComObject(CLSID_TaskbarList) as ITaskbarList3;
  77.  
  78. end;
  79.  
  80. end.

Handoko

  • Hero Member
  • *****
  • Posts: 3185
  • My goal: build my own game engine using Lazarus
Re: Task Icon Progress Bar under Windows
« Reply #1 on: March 31, 2019, 01:14:09 pm »
I ever wondered how to do it.
Thanks for sharing it

440bx

  • Hero Member
  • *****
  • Posts: 1194
Re: Task Icon Progress Bar under Windows
« Reply #2 on: March 31, 2019, 02:17:34 pm »
Yes, thank you for sharing that.  Very nice.
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.