SystemTray.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /////////////////////////////////////////////////////////////////////////////
  2. // SystemTray.h : header file
  3. //
  4. // Written by Chris Maunder ([email protected])
  5. // Copyright (c) 1998.
  6. //
  7. // This code may be used in compiled form in any way you desire. This
  8. // file may be redistributed unmodified by any means PROVIDING it is
  9. // not sold for profit without the authors written consent, and
  10. // providing that this notice and the authors name is included. If
  11. // the source code in this file is used in any commercial application
  12. // then acknowledgement must be made to the author of this file
  13. // (in whatever form you wish).
  14. //
  15. // This file is provided "as is" with no expressed or implied warranty.
  16. //
  17. // Expect bugs.
  18. //
  19. // Please use and enjoy. Please let me know of any bugs/mods/improvements
  20. // that you have found/implemented and I will fix/incorporate them into this
  21. // file.
  22. #ifndef _INCLUDED_SYSTEMTRAY_H_
  23. #define _INCLUDED_SYSTEMTRAY_H_
  24. #define ASSUME_IE5_OR_ABOVE
  25. #ifdef ASSUME_IE5_OR_ABOVE
  26. # ifndef _WIN32_IE
  27. # define _WIN32_IE 0x0500 // enable shell v5 features
  28. # elif _WIN32_IE < 0x0500
  29. # undef _WIN32_IE
  30. # define _WIN32_IE 0x0500 // enable shell v5 features
  31. # endif
  32. # ifdef NOTIFYICONDATA_V1_SIZE // If NOTIFYICONDATA_V1_SIZE, then we can use fun stuff
  33. # define SYSTEMTRAY_USEW2K
  34. # endif
  35. #endif
  36. #ifndef NIIF_NONE
  37. #define NIIF_NONE 0
  38. #endif
  39. #define WM_CUSTOMIZE_TRAY_MENU WM_USER + 215
  40. #define WM_TRAY_MENU_MOUSE_MOVE WM_USER + 216
  41. // #include <afxwin.h>
  42. #include <afxtempl.h>
  43. #include <afxdisp.h> // COleDateTime
  44. #include "TrayWnd.h"
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CSystemTray window
  47. class CSystemTray : public CWnd
  48. {
  49. // Construction/destruction
  50. public:
  51. CSystemTray();
  52. CSystemTray(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID,
  53. BOOL bhidden = FALSE,
  54. LPCTSTR szBalloonTip = NULL, LPCTSTR szBalloonTitle = NULL,
  55. DWORD dwBalloonIcon = NIIF_NONE, UINT uBalloonTimeout = 10);
  56. virtual ~CSystemTray();
  57. DECLARE_DYNAMIC(CSystemTray)
  58. // Operations
  59. public:
  60. BOOL Enabled() { return m_bEnabled; }
  61. BOOL Visible() { return !m_bHidden; }
  62. // Create the tray icon
  63. BOOL Create(CWnd* pParent, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID,
  64. BOOL bHidden = FALSE,
  65. LPCTSTR szBalloonTip = NULL, LPCTSTR szBalloonTitle = NULL,
  66. DWORD dwBalloonIcon = NIIF_NONE, UINT uBalloonTimeout = 10);
  67. // Change or retrieve the Tooltip text
  68. BOOL SetTooltipText(LPCTSTR pszTooltipText);
  69. BOOL SetTooltipText(UINT nID);
  70. CString GetTooltipText() const;
  71. // Change or retrieve the icon displayed
  72. BOOL SetIcon(HICON hIcon);
  73. BOOL SetIcon(LPCTSTR lpszIconName);
  74. BOOL SetIcon(UINT nIDResource);
  75. BOOL SetStandardIcon(LPCTSTR lpIconName);
  76. BOOL SetStandardIcon(UINT nIDResource);
  77. HICON GetIcon() const;
  78. void SetFocus();
  79. BOOL HideIcon();
  80. BOOL ShowIcon();
  81. BOOL AddIcon();
  82. BOOL RemoveIcon();
  83. BOOL MoveToRight();
  84. BOOL ShowBalloon(LPCTSTR szText, LPCTSTR szTitle = NULL,
  85. DWORD dwIcon = NIIF_NONE, UINT uTimeout = 10);
  86. // For icon animation
  87. BOOL SetIconList(UINT uFirstIconID, UINT uLastIconID);
  88. BOOL SetIconList(HICON* pHIconList, UINT nNumIcons);
  89. BOOL Animate(UINT nDelayMilliSeconds, int nNumSeconds = -1);
  90. BOOL StepAnimation();
  91. BOOL StopAnimation();
  92. // Change menu default item
  93. void GetMenuDefaultItem(UINT& uItem, BOOL& bByPos);
  94. BOOL SetMenuDefaultItem(UINT uItem, BOOL bByPos);
  95. // Change or retrieve the window to send notification messages to
  96. BOOL SetNotificationWnd(CWnd* pNotifyWnd);
  97. CWnd* GetNotificationWnd() const;
  98. // Change or retrieve the window to send menu commands to
  99. BOOL SetTargetWnd(CWnd* pTargetWnd);
  100. CWnd* GetTargetWnd() const;
  101. // Change or retrieve notification messages sent to the window
  102. BOOL SetCallbackMessage(UINT uCallbackMessage);
  103. UINT GetCallbackMessage() const;
  104. UINT GetTimerID() const { return m_nTimerID; }
  105. void SetSingleClickSelect(BOOL bSel) { m_bSingleClickSelect = bSel; }
  106. BOOL GetSingleClickSelect() { return m_bSingleClickSelect; }
  107. // Static functions
  108. public:
  109. static void MinimiseToTray(CWnd* pWnd);
  110. static void MaximiseFromTray(CWnd* pWnd);
  111. public:
  112. // Default handler for tray notification message
  113. virtual LRESULT OnTrayNotification(WPARAM uID, LPARAM lEvent);
  114. // Overrides
  115. // ClassWizard generated virtual function overrides
  116. //{{AFX_VIRTUAL(CSystemTray)
  117. protected:
  118. virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  119. //}}AFX_VIRTUAL
  120. // Implementation
  121. protected:
  122. void Initialise();
  123. void InstallIconPending();
  124. // Implementation
  125. protected:
  126. NOTIFYICONDATA m_tnd;
  127. BOOL m_bEnabled; // does O/S support tray icon?
  128. BOOL m_bHidden; // Has the icon been hidden?
  129. BOOL m_bRemoved; // Has the icon been removed?
  130. BOOL m_bShowIconPending; // Show the icon once tha taskbar has been created
  131. BOOL m_bWin2K; // Use new W2K features?
  132. CWnd* m_pTargetWnd; // Window that menu commands are sent
  133. CArray<HICON, HICON> m_IconList;
  134. UINT m_uIDTimer;
  135. int m_nCurrentIcon;
  136. COleDateTime m_StartTime;
  137. int m_nAnimationPeriod;
  138. HICON m_hSavedIcon;
  139. UINT m_DefaultMenuItemID;
  140. BOOL m_DefaultMenuItemByPos;
  141. UINT m_uCreationFlags;
  142. BOOL m_bSingleClickSelect;
  143. // Static data
  144. protected:
  145. static BOOL RemoveTaskbarIcon(CWnd* pWnd);
  146. static const UINT m_nTimerID;
  147. static UINT m_nMaxTooltipLength;
  148. static const UINT m_nTaskbarCreatedMsg;
  149. static CTrayWnd m_wndInvisible;
  150. static BOOL m_bShowWndAnimation;
  151. static BOOL GetW2K();
  152. #ifndef _WIN32_WCE
  153. static void GetTrayWndRect(LPRECT lprect);
  154. static BOOL GetDoWndAnimation();
  155. #endif
  156. // Generated message map functions
  157. protected:
  158. //{{AFX_MSG(CSystemTray)
  159. afx_msg void OnTimer(UINT_PTR nIDEvent);
  160. //}}AFX_MSG
  161. #ifndef _WIN32_WCE
  162. afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection);
  163. #endif
  164. LRESULT OnTaskbarCreated(WPARAM wParam, LPARAM lParam);
  165. DECLARE_MESSAGE_MAP()
  166. };
  167. #endif
  168. /////////////////////////////////////////////////////////////////////////////