2
0

TaskbarProgressFunc.pas 2.1 KB

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