TaskbarProgressFunc.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. ActiveX, Forms, ShlObj;
  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_ITaskbarList3, 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 and Assigned(Application.MainForm) and
  42. Application.MainForm.HandleAllocated then
  43. TaskbarListInterface.SetProgressState(Application.MainForm.Handle, StateFlags[State]);
  44. end;
  45. procedure SetAppTaskbarProgressValue(const Completed, Total: Cardinal);
  46. begin
  47. if InitializeTaskbarList and Assigned(Application.MainForm) and
  48. Application.MainForm.HandleAllocated then
  49. TaskbarListInterface.SetProgressValue(Application.MainForm.Handle, Completed, Total);
  50. end;
  51. end.