Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
3.8 KiB

  1. #include "priv.h"
  2. #include "resource.h"
  3. #include <trayp.h>
  4. class TaskbarList : public ITaskbarList2
  5. {
  6. public:
  7. TaskbarList();
  8. // IUnknown Methods
  9. STDMETHODIMP QueryInterface(REFIID,void **);
  10. STDMETHODIMP_(ULONG) AddRef(void);
  11. STDMETHODIMP_(ULONG) Release(void);
  12. // ITaskbarList Methods
  13. STDMETHODIMP HrInit(void);
  14. STDMETHODIMP AddTab(HWND hwnd);
  15. STDMETHODIMP DeleteTab(HWND hwnd);
  16. STDMETHODIMP ActivateTab(HWND hwnd);
  17. STDMETHODIMP SetActiveAlt(HWND hwnd);
  18. // ITaskbarList2 Methods
  19. STDMETHODIMP MarkFullscreenWindow(HWND hwnd, BOOL fFullscreen);
  20. protected:
  21. ~TaskbarList();
  22. HWND _HwndGetTaskbarList(void);
  23. UINT _cRef;
  24. HWND _hwndTaskbarList;
  25. int _wm_shellhook;
  26. };
  27. //////////////////////////////////////////////////////////////////////////////
  28. //
  29. // TaskbarList Object
  30. //
  31. //////////////////////////////////////////////////////////////////////////////
  32. STDAPI TaskbarList_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi)
  33. {
  34. // aggregation checking is handled in class factory
  35. TaskbarList *pTL = new TaskbarList();
  36. if (pTL)
  37. {
  38. *ppunk = SAFECAST(pTL, IUnknown *);
  39. return S_OK;
  40. }
  41. return E_OUTOFMEMORY;
  42. }
  43. TaskbarList::TaskbarList()
  44. {
  45. _cRef = 1;
  46. _hwndTaskbarList = NULL;
  47. _wm_shellhook = RegisterWindowMessage(TEXT("SHELLHOOK"));
  48. DllAddRef();
  49. }
  50. TaskbarList::~TaskbarList()
  51. {
  52. ASSERT(_cRef == 0); // should always have zero
  53. DllRelease();
  54. }
  55. HWND TaskbarList::_HwndGetTaskbarList(void)
  56. {
  57. if (_hwndTaskbarList && IsWindow(_hwndTaskbarList))
  58. return _hwndTaskbarList;
  59. _hwndTaskbarList = FindWindow(TEXT("Shell_TrayWnd"), NULL);
  60. if (_hwndTaskbarList)
  61. _hwndTaskbarList = (HWND)SendMessage(_hwndTaskbarList, WMTRAY_QUERY_VIEW, 0, 0);
  62. return _hwndTaskbarList;
  63. }
  64. //////////////////////////////////
  65. //
  66. // IUnknown Methods...
  67. //
  68. HRESULT TaskbarList::QueryInterface(REFIID iid, void **ppv)
  69. {
  70. static const QITAB qit[] =
  71. {
  72. QITABENT(TaskbarList, ITaskbarList),
  73. QITABENT(TaskbarList, ITaskbarList2),
  74. { 0 },
  75. };
  76. return QISearch(this, qit, iid, ppv);
  77. }
  78. ULONG TaskbarList::AddRef()
  79. {
  80. return ++_cRef;
  81. }
  82. ULONG TaskbarList::Release()
  83. {
  84. if (--_cRef)
  85. return _cRef;
  86. delete this;
  87. return 0;
  88. }
  89. //////////////////////////////////
  90. //
  91. // ITaskbarList Methods...
  92. //
  93. HRESULT TaskbarList::HrInit(void)
  94. {
  95. HWND hwndTL = _HwndGetTaskbarList();
  96. if (hwndTL == NULL)
  97. return E_NOTIMPL;
  98. return S_OK;
  99. }
  100. HRESULT TaskbarList::AddTab(HWND hwnd)
  101. {
  102. HWND hwndTL = _HwndGetTaskbarList();
  103. if (hwndTL)
  104. SendMessage(hwndTL, _wm_shellhook, HSHELL_WINDOWCREATED, (LPARAM) hwnd);
  105. return S_OK;
  106. }
  107. HRESULT TaskbarList::DeleteTab(HWND hwnd)
  108. {
  109. HWND hwndTL = _HwndGetTaskbarList();
  110. if (hwndTL)
  111. SendMessage(hwndTL, _wm_shellhook, HSHELL_WINDOWDESTROYED, (LPARAM) hwnd);
  112. return S_OK;
  113. }
  114. HRESULT TaskbarList::ActivateTab(HWND hwnd)
  115. {
  116. HWND hwndTL = _HwndGetTaskbarList();
  117. if (hwndTL)
  118. {
  119. SendMessage(hwndTL, _wm_shellhook, HSHELL_WINDOWACTIVATED, (LPARAM) hwnd);
  120. SendMessage(hwndTL, TBC_SETACTIVEALT , 0, (LPARAM) hwnd);
  121. }
  122. return S_OK;
  123. }
  124. HRESULT TaskbarList::SetActiveAlt(HWND hwnd)
  125. {
  126. HWND hwndTL = _HwndGetTaskbarList();
  127. if (hwndTL)
  128. SendMessage(hwndTL, TBC_SETACTIVEALT , 0, (LPARAM) hwnd);
  129. return S_OK;
  130. }
  131. HRESULT TaskbarList::MarkFullscreenWindow(HWND hwnd, BOOL fFullscreen)
  132. {
  133. if (GetUIVersion() >= 6)
  134. {
  135. HWND hwndTL = _HwndGetTaskbarList();
  136. if (hwndTL)
  137. SendMessage(hwndTL, TBC_MARKFULLSCREEN, (WPARAM) fFullscreen, (LPARAM) hwnd);
  138. return S_OK;
  139. }
  140. return E_FAIL; // ITaskbarList2 not supported downlevel
  141. };