dwtaskbarlist.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. unit dwTaskbarList;
  2. {$mode delphi}{$H+}
  3. interface
  4. uses
  5. Messages
  6. , Windows
  7. ;
  8. const
  9. CLSID_TaskbarList: TGUID = '{56FDF344-FD6D-11D0-958A-006097C9A090}';
  10. CLSID_TaskbarList2: TGUID = '{602D4995-B13A-429B-A66E-1935E44F4317}';
  11. CLSID_TaskbarList3: TGUID = '{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}';
  12. const
  13. THBF_ENABLED = $0000;
  14. THBF_DISABLED = $0001;
  15. THBF_DISMISSONCLICK = $0002;
  16. THBF_NOBACKGROUND = $0004;
  17. THBF_HIDDEN = $0008;
  18. const
  19. THB_BITMAP = $0001;
  20. THB_ICON = $0002;
  21. THB_TOOLTIP = $0004;
  22. THB_FLAGS = $0008;
  23. const
  24. THBN_CLICKED = $1800;
  25. const
  26. TBPF_NOPROGRESS = $00;
  27. TBPF_INDETERMINATE = $01;
  28. TBPF_NORMAL = $02;
  29. TBPF_ERROR= $04;
  30. TBPF_PAUSED = $08;
  31. const
  32. TBATF_USEMDITHUMBNAIL: DWORD = $00000001;
  33. TBATF_USEMDILIVEPREVIEW: DWORD = $00000002;
  34. const
  35. WM_DWMSENDICONICTHUMBNAIL = $0323;
  36. WM_DWMSENDICONICLIVEPREVIEWBITMAP = $0326;
  37. type
  38. TTipString = array[0..259] of WideChar;
  39. PTipString = ^TTipString;
  40. tagTHUMBBUTTON = packed record
  41. dwMask
  42. : DWORD;
  43. iId
  44. , iBitmap
  45. : UINT;
  46. hIcon
  47. : HICON;
  48. szTip
  49. : TTipString;
  50. dwFlags
  51. : DWORD;
  52. end;
  53. THUMBBUTTON = tagTHUMBBUTTON;
  54. THUMBBUTTONLIST = ^THUMBBUTTON;
  55. TThumbButton = THUMBBUTTON;
  56. TThumbButtonList = array of TThumbButton;
  57. type
  58. ITaskbarList = interface
  59. ['{56FDF342-FD6D-11D0-958A-006097C9A090}']
  60. procedure HrInit; safecall;
  61. procedure AddTab(hwnd: HWND); safecall;
  62. procedure DeleteTab(hwnd: HWND); safecall;
  63. procedure ActivateTab(hwnd: HWND); safecall;
  64. procedure SetActiveAlt(hwnd: HWND); safecall;
  65. end;
  66. ITaskbarList2 = interface(ITaskbarList)
  67. ['{602D4995-B13A-429B-A66E-1935E44F4317}']
  68. procedure MarkFullscreenWindow(hwnd: HWND; fFullscreen: Bool); safecall;
  69. end;
  70. ITaskbarList3 = interface(ITaskbarList2)
  71. ['{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}']
  72. procedure SetProgressValue(hwnd: HWND; ullCompleted, ullTotal: ULONGLONG); safecall;
  73. procedure SetProgressState(hwnd: HWND; tbpFlags: DWORD); safecall;
  74. procedure RegisterTab(hwndTab: HWND; hwndMDI: HWND); safecall;
  75. procedure UnregisterTab(hwndTab: HWND); safecall;
  76. procedure SetTabOrder(hwndTab: HWND; hwndInsertBefore: HWND); safecall;
  77. procedure SetTabActive(hwndTab: HWND; hwndMDI: HWND; tbatFlags: DWORD); safecall;
  78. procedure ThumbBarAddButtons(hwnd: HWND; cButtons: UINT; Button: THUMBBUTTONLIST); safecall;
  79. procedure ThumbBarUpdateButtons(hwnd: HWND; cButtons: UINT; pButton: THUMBBUTTONLIST); safecall;
  80. procedure ThumbBarSetImageList(hwnd: HWND; himl: HIMAGELIST); safecall;
  81. procedure SetOverlayIcon(hwnd: HWND; hIcon: HICON; pszDescription: LPCWSTR); safecall;
  82. procedure SetThumbnailTooltip(hwnd: HWND; pszTip: LPCWSTR); safecall;
  83. procedure SetThumbnailClip(hwnd: HWND; prcClip: PRect); safecall;
  84. end;
  85. const
  86. DWM_SIT_DISPLAYFRAME = $00000001; // Display a window frame around the provided bitmap
  87. DWMWA_FORCE_ICONIC_REPRESENTATION = 7; // [set] Force this window to display iconic thumbnails.
  88. DWMWA_HAS_ICONIC_BITMAP = 10; // [set] Indicates an available bitmap when there is no better thumbnail representation.
  89. DWMWA_DISALLOW_PEEK = 11; // [set] Don't invoke Peek on the window.
  90. type
  91. TWMDwmSendIconicLivePreviewBitmap = TWMNoParams;
  92. TWMDwmSendIconicThumbnail = packed record
  93. Msg
  94. : Cardinal;
  95. Unused
  96. : Integer;
  97. Height
  98. , Width
  99. : Word;
  100. Result
  101. : LongInt;
  102. end;
  103. function DwmInvalidateIconicBitmaps(hwnd: HWND): HRESULT;
  104. function DwmSetIconicLivePreviewBitmap(hwnd: HWND; hbmp: HBITMAP; pptClient: PPoint; dwSITFlags: DWORD): HRESULT;
  105. function DwmSetIconicThumbnail(hWnd: HWND; hBmp: HBITMAP; dwSITFlags: DWORD): HRESULT;
  106. function DwmSetWindowAttribute(hwnd: HWND; dwAttribute: DWORD; pvAttribute: Pointer; cbAttribute: DWORD): HRESULT;
  107. function PrintWindow(hwnd: HWND; hdcBlt: HDC; nFlags: UINT): BOOL;
  108. implementation
  109. var
  110. hDWMAPI: HMODULE;
  111. _DwmInvalidateIconicBitmaps: function(hwnd: HWND): HRESULT; stdcall;
  112. _DwmSetIconicThumbnail: function(hWnd: HWND; hBmp: HBITMAP; dwSITFlags: DWORD): HRESULT; stdcall;
  113. _DwmSetIconicLivePreviewBitmap: function(hwnd: HWND; hbmp: HBITMAP; pptClient: PPoint; dwSITFlags: DWORD): HRESULT; stdcall;
  114. _DwmSetWindowAttribute: function(hwnd: HWND; dwAttribute: DWORD; pvAttribute: Pointer; cbAttribute: DWORD): HRESULT; stdcall;
  115. _PrintWindow: function(hwnd: HWND; hdcBlt: HDC; nFlags: UINT): BOOL; stdcall;
  116. procedure InitDwmApi;
  117. begin
  118. if hDWMAPI = 0 then
  119. begin
  120. hDWMAPI := LoadLibrary('DWMAPI.DLL');
  121. if hDWMAPI = 0 then
  122. begin
  123. hDWMAPI := THandle(-1);
  124. end
  125. else
  126. begin
  127. _DwmInvalidateIconicBitmaps := GetProcAddress(hDWMAPI, 'DwmInvalidateIconicBitmaps');
  128. _DwmSetIconicLivePreviewBitmap := GetProcAddress(hDWMAPI, 'DwmSetIconicLivePreviewBitmap');
  129. _DwmSetIconicThumbnail := GetProcAddress(hDWMAPI, 'DwmSetIconicThumbnail');
  130. _DwmSetWindowAttribute := GetProcAddress(hDWMAPI, 'DwmSetWindowAttribute');
  131. end;
  132. end;
  133. end;
  134. function DwmInvalidateIconicBitmaps(hwnd: HWND): HRESULT;
  135. begin
  136. InitDwmApi;
  137. if Assigned(_DwmInvalidateIconicBitmaps) then
  138. Result := _DwmInvalidateIconicBitmaps(hwnd)
  139. else
  140. Result := E_NOTIMPL;
  141. end;
  142. function DwmSetIconicLivePreviewBitmap(hwnd: HWND; hbmp: HBITMAP; pptClient: PPoint; dwSITFlags: DWORD): HRESULT;
  143. begin
  144. InitDwmApi;
  145. if Assigned(_DwmSetIconicLivePreviewBitmap) then
  146. Result := _DwmSetIconicLivePreviewBitmap(hwnd, hbmp, pptClient, dwSITFlags)
  147. else
  148. Result := E_NOTIMPL;
  149. end;
  150. function DwmSetIconicThumbnail(hWnd: HWND; hBmp: HBITMAP; dwSITFlags: DWORD): HRESULT;
  151. begin
  152. InitDwmApi;
  153. if Assigned(_DwmSetIconicThumbnail) then
  154. Result := _DwmSetIconicThumbnail(hWnd, hBmp, dwSITFlags)
  155. else
  156. Result := E_NOTIMPL;
  157. end;
  158. function DwmSetWindowAttribute(hwnd: HWND; dwAttribute: DWORD; pvAttribute: Pointer; cbAttribute: DWORD): HRESULT;
  159. begin
  160. InitDwmApi;
  161. if Assigned(_DwmSetWindowAttribute) then
  162. Result := _DwmSetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute)
  163. else
  164. Result := E_NOTIMPL;
  165. end;
  166. {-----------------------------------------------}
  167. function PrintWindow(hwnd: HWND; hdcBlt: HDC; nFlags: UINT): BOOL;
  168. begin
  169. if Assigned(_PrintWindow) then
  170. begin
  171. Result := _PrintWindow(hwnd, hdcBlt, nFlags);
  172. end
  173. else
  174. begin
  175. _PrintWindow := GetProcAddress(GetModuleHandle('user32.dll'), 'PrintWindow');
  176. Result := Assigned(_PrintWindow) and _PrintWindow(hwnd, hdcBlt, nFlags);
  177. end;
  178. end;
  179. end.