TaskbarProgressFunc.pas 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. unit TaskbarProgressFunc;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2024 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Wrappers for ITaskbarList3.SetProgressState & SetProgressValue
  8. }
  9. interface
  10. type
  11. TTaskbarProgressState = (tpsNoProgress, tpsIndeterminate, tpsNormal,
  12. tpsError, tpsPaused);
  13. procedure SetAppTaskbarProgressState(const State: TTaskbarProgressState);
  14. procedure SetAppTaskbarProgressValue(const Completed, Total: Cardinal);
  15. implementation
  16. uses
  17. Windows, ActiveX, Forms, dwTaskbarList;
  18. var
  19. TaskbarListInitialized: Boolean;
  20. TaskbarListInterface: ITaskbarList3;
  21. function InitializeTaskbarList: Boolean;
  22. var
  23. Intf: ITaskbarList3;
  24. begin
  25. if not TaskbarListInitialized then begin
  26. if CoCreateInstance(CLSID_TaskbarList, nil, CLSCTX_INPROC_SERVER, IID_TaskbarList3, Intf) = S_OK then
  27. if Intf.HrInit = S_OK then begin
  28. { Safety: don't allow the instance to be destroyed at shutdown }
  29. Intf._AddRef;
  30. TaskbarListInterface := Intf;
  31. end;
  32. TaskbarListInitialized := True;
  33. end;
  34. Result := Assigned(TaskbarListInterface);
  35. end;
  36. procedure SetAppTaskbarProgressState(const State: TTaskbarProgressState);
  37. const
  38. StateFlags: array[TTaskbarProgressState] of Integer = (
  39. TBPF_NOPROGRESS, TBPF_INDETERMINATE, TBPF_NORMAL, TBPF_ERROR, TBPF_PAUSED);
  40. begin
  41. if InitializeTaskbarList then
  42. TaskbarListInterface.SetProgressState(Application.Handle, StateFlags[State]);
  43. end;
  44. procedure SetAppTaskbarProgressValue(const Completed, Total: Cardinal);
  45. var
  46. Completed64, Total64: dwInteger64;
  47. begin
  48. if InitializeTaskbarList then begin
  49. Completed64.Lo := Completed;
  50. Completed64.Hi := 0;
  51. Total64.Lo := Total;
  52. Total64.Hi := 0;
  53. TaskbarListInterface.SetProgressValue(Application.Handle, Completed64, Total64);
  54. end;
  55. end;
  56. end.