SystemTray.h 6.2 KB

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