SystemTray.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. /////////////////////////////////////////////////////////////////////////////
  45. // CSystemTray window
  46. class CSystemTray : public CWnd
  47. {
  48. // Construction/destruction
  49. public:
  50. CSystemTray();
  51. CSystemTray(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID,
  52. BOOL bhidden = FALSE,
  53. LPCTSTR szBalloonTip = NULL, LPCTSTR szBalloonTitle = NULL,
  54. DWORD dwBalloonIcon = NIIF_NONE, UINT uBalloonTimeout = 10);
  55. virtual ~CSystemTray();
  56. DECLARE_DYNAMIC(CSystemTray)
  57. // Operations
  58. public:
  59. BOOL Enabled() { return m_bEnabled; }
  60. BOOL Visible() { return !m_bHidden; }
  61. // Create the tray icon
  62. BOOL Create(CWnd* pParent, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID,
  63. BOOL bHidden = FALSE,
  64. LPCTSTR szBalloonTip = NULL, LPCTSTR szBalloonTitle = NULL,
  65. DWORD dwBalloonIcon = NIIF_NONE, UINT uBalloonTimeout = 10);
  66. // Change or retrieve the Tooltip text
  67. BOOL SetTooltipText(LPCTSTR pszTooltipText);
  68. BOOL SetTooltipText(UINT nID);
  69. CString GetTooltipText() const;
  70. // Change or retrieve the icon displayed
  71. BOOL SetIcon(HICON hIcon);
  72. BOOL SetIcon(LPCTSTR lpszIconName);
  73. BOOL SetIcon(UINT nIDResource);
  74. BOOL SetStandardIcon(LPCTSTR lpIconName);
  75. BOOL SetStandardIcon(UINT nIDResource);
  76. HICON GetIcon() const;
  77. void SetFocus();
  78. BOOL HideIcon();
  79. BOOL ShowIcon();
  80. BOOL AddIcon();
  81. BOOL RemoveIcon();
  82. BOOL MoveToRight();
  83. BOOL ShowBalloon(LPCTSTR szText, LPCTSTR szTitle = NULL,
  84. DWORD dwIcon = NIIF_NONE, UINT uTimeout = 10);
  85. // For icon animation
  86. BOOL SetIconList(UINT uFirstIconID, UINT uLastIconID);
  87. BOOL SetIconList(HICON* pHIconList, UINT nNumIcons);
  88. BOOL Animate(UINT nDelayMilliSeconds, int nNumSeconds = -1);
  89. BOOL StepAnimation();
  90. BOOL StopAnimation();
  91. // Change menu default item
  92. void GetMenuDefaultItem(UINT& uItem, BOOL& bByPos);
  93. BOOL SetMenuDefaultItem(UINT uItem, BOOL bByPos);
  94. // Change or retrieve the window to send notification messages to
  95. BOOL SetNotificationWnd(CWnd* pNotifyWnd);
  96. CWnd* GetNotificationWnd() const;
  97. // Change or retrieve the window to send menu commands to
  98. BOOL SetTargetWnd(CWnd* pTargetWnd);
  99. CWnd* GetTargetWnd() const;
  100. // Change or retrieve notification messages sent to the window
  101. BOOL SetCallbackMessage(UINT uCallbackMessage);
  102. UINT GetCallbackMessage() const;
  103. UINT GetTimerID() const { return m_nTimerID; }
  104. void SetSingleClickSelect(BOOL bSel) { m_bSingleClickSelect = bSel; }
  105. BOOL GetSingleClickSelect() { return m_bSingleClickSelect; }
  106. // Static functions
  107. public:
  108. static void MinimiseToTray(CWnd* pWnd);
  109. static void MaximiseFromTray(CWnd* pWnd);
  110. public:
  111. // Default handler for tray notification message
  112. virtual LRESULT OnTrayNotification(WPARAM uID, LPARAM lEvent);
  113. // Overrides
  114. // ClassWizard generated virtual function overrides
  115. //{{AFX_VIRTUAL(CSystemTray)
  116. protected:
  117. virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  118. //}}AFX_VIRTUAL
  119. // Implementation
  120. protected:
  121. void Initialise();
  122. void InstallIconPending();
  123. // Implementation
  124. protected:
  125. NOTIFYICONDATA m_tnd;
  126. BOOL m_bEnabled; // does O/S support tray icon?
  127. BOOL m_bHidden; // Has the icon been hidden?
  128. BOOL m_bRemoved; // Has the icon been removed?
  129. BOOL m_bShowIconPending; // Show the icon once tha taskbar has been created
  130. BOOL m_bWin2K; // Use new W2K features?
  131. CWnd* m_pTargetWnd; // Window that menu commands are sent
  132. CArray<HICON, HICON> m_IconList;
  133. UINT m_uIDTimer;
  134. int m_nCurrentIcon;
  135. COleDateTime m_StartTime;
  136. int m_nAnimationPeriod;
  137. HICON m_hSavedIcon;
  138. UINT m_DefaultMenuItemID;
  139. BOOL m_DefaultMenuItemByPos;
  140. UINT m_uCreationFlags;
  141. BOOL m_bSingleClickSelect;
  142. // Static data
  143. protected:
  144. static BOOL RemoveTaskbarIcon(CWnd* pWnd);
  145. static const UINT m_nTimerID;
  146. static UINT m_nMaxTooltipLength;
  147. static const UINT m_nTaskbarCreatedMsg;
  148. static CWnd m_wndInvisible;
  149. static BOOL m_bShowWndAnimation;
  150. static BOOL GetW2K();
  151. #ifndef _WIN32_WCE
  152. static void GetTrayWndRect(LPRECT lprect);
  153. static BOOL GetDoWndAnimation();
  154. #endif
  155. // Generated message map functions
  156. protected:
  157. //{{AFX_MSG(CSystemTray)
  158. afx_msg void OnTimer(UINT_PTR nIDEvent);
  159. //}}AFX_MSG
  160. #ifndef _WIN32_WCE
  161. afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection);
  162. #endif
  163. LRESULT OnTaskbarCreated(WPARAM wParam, LPARAM lParam);
  164. DECLARE_MESSAGE_MAP()
  165. };
  166. #endif
  167. /////////////////////////////////////////////////////////////////////////////