| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- /////////////////////////////////////////////////////////////////////////////
- // SystemTray.h : header file
- //
- // Written by Chris Maunder ([email protected])
- // Copyright (c) 1998.
- //
- // This code may be used in compiled form in any way you desire. This
- // file may be redistributed unmodified by any means PROVIDING it is
- // not sold for profit without the authors written consent, and
- // providing that this notice and the authors name is included. If
- // the source code in this file is used in any commercial application
- // then acknowledgement must be made to the author of this file
- // (in whatever form you wish).
- //
- // This file is provided "as is" with no expressed or implied warranty.
- //
- // Expect bugs.
- //
- // Please use and enjoy. Please let me know of any bugs/mods/improvements
- // that you have found/implemented and I will fix/incorporate them into this
- // file.
- #ifndef _INCLUDED_SYSTEMTRAY_H_
- #define _INCLUDED_SYSTEMTRAY_H_
- #define ASSUME_IE5_OR_ABOVE
- #ifdef ASSUME_IE5_OR_ABOVE
- # ifndef _WIN32_IE
- # define _WIN32_IE 0x0500 // enable shell v5 features
- # elif _WIN32_IE < 0x0500
- # undef _WIN32_IE
- # define _WIN32_IE 0x0500 // enable shell v5 features
- # endif
- # ifdef NOTIFYICONDATA_V1_SIZE // If NOTIFYICONDATA_V1_SIZE, then we can use fun stuff
- # define SYSTEMTRAY_USEW2K
- # endif
- #endif
- #ifndef NIIF_NONE
- #define NIIF_NONE 0
- #endif
- #define WM_CUSTOMIZE_TRAY_MENU WM_USER + 215
- #define WM_TRAY_MENU_MOUSE_MOVE WM_USER + 216
- // #include <afxwin.h>
- #include <afxtempl.h>
- #include <afxdisp.h> // COleDateTime
- #include "TrayWnd.h"
- /////////////////////////////////////////////////////////////////////////////
- // CSystemTray window
- class CSystemTray : public CWnd
- {
- // Construction/destruction
- public:
- CSystemTray();
- CSystemTray(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID,
- BOOL bhidden = FALSE,
- LPCTSTR szBalloonTip = NULL, LPCTSTR szBalloonTitle = NULL,
- DWORD dwBalloonIcon = NIIF_NONE, UINT uBalloonTimeout = 10);
- virtual ~CSystemTray();
- DECLARE_DYNAMIC(CSystemTray)
- // Operations
- public:
- BOOL Enabled() { return m_bEnabled; }
- BOOL Visible() { return !m_bHidden; }
- // Create the tray icon
- BOOL Create(CWnd* pParent, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID,
- BOOL bHidden = FALSE,
- LPCTSTR szBalloonTip = NULL, LPCTSTR szBalloonTitle = NULL,
- DWORD dwBalloonIcon = NIIF_NONE, UINT uBalloonTimeout = 10);
- // Change or retrieve the Tooltip text
- BOOL SetTooltipText(LPCTSTR pszTooltipText);
- BOOL SetTooltipText(UINT nID);
- CString GetTooltipText() const;
- // Change or retrieve the icon displayed
- BOOL SetIcon(HICON hIcon);
- BOOL SetIcon(LPCTSTR lpszIconName);
- BOOL SetIcon(UINT nIDResource);
- BOOL SetStandardIcon(LPCTSTR lpIconName);
- BOOL SetStandardIcon(UINT nIDResource);
- HICON GetIcon() const;
- void SetFocus();
- BOOL HideIcon();
- BOOL ShowIcon();
- BOOL AddIcon();
- BOOL RemoveIcon();
- BOOL MoveToRight();
- BOOL ShowBalloon(LPCTSTR szText, LPCTSTR szTitle = NULL,
- DWORD dwIcon = NIIF_NONE, UINT uTimeout = 10);
- // For icon animation
- BOOL SetIconList(UINT uFirstIconID, UINT uLastIconID);
- BOOL SetIconList(HICON* pHIconList, UINT nNumIcons);
- BOOL Animate(UINT nDelayMilliSeconds, int nNumSeconds = -1);
- BOOL StepAnimation();
- BOOL StopAnimation();
- // Change menu default item
- void GetMenuDefaultItem(UINT& uItem, BOOL& bByPos);
- BOOL SetMenuDefaultItem(UINT uItem, BOOL bByPos);
- // Change or retrieve the window to send notification messages to
- BOOL SetNotificationWnd(CWnd* pNotifyWnd);
- CWnd* GetNotificationWnd() const;
- // Change or retrieve the window to send menu commands to
- BOOL SetTargetWnd(CWnd* pTargetWnd);
- CWnd* GetTargetWnd() const;
- // Change or retrieve notification messages sent to the window
- BOOL SetCallbackMessage(UINT uCallbackMessage);
- UINT GetCallbackMessage() const;
- UINT GetTimerID() const { return m_nTimerID; }
- void SetSingleClickSelect(BOOL bSel) { m_bSingleClickSelect = bSel; }
- BOOL GetSingleClickSelect() { return m_bSingleClickSelect; }
-
- // Static functions
- public:
- static void MinimiseToTray(CWnd* pWnd);
- static void MaximiseFromTray(CWnd* pWnd);
- public:
- // Default handler for tray notification message
- virtual LRESULT OnTrayNotification(WPARAM uID, LPARAM lEvent);
- // Overrides
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CSystemTray)
- protected:
- virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- void Initialise();
- void InstallIconPending();
- // Implementation
- protected:
- NOTIFYICONDATA m_tnd;
- BOOL m_bEnabled; // does O/S support tray icon?
- BOOL m_bHidden; // Has the icon been hidden?
- BOOL m_bRemoved; // Has the icon been removed?
- BOOL m_bShowIconPending; // Show the icon once tha taskbar has been created
- BOOL m_bWin2K; // Use new W2K features?
- CWnd* m_pTargetWnd; // Window that menu commands are sent
- CArray<HICON, HICON> m_IconList;
- UINT m_uIDTimer;
- int m_nCurrentIcon;
- COleDateTime m_StartTime;
- int m_nAnimationPeriod;
- HICON m_hSavedIcon;
- UINT m_DefaultMenuItemID;
- BOOL m_DefaultMenuItemByPos;
- UINT m_uCreationFlags;
- BOOL m_bSingleClickSelect;
-
- // Static data
- protected:
- static BOOL RemoveTaskbarIcon(CWnd* pWnd);
- static const UINT m_nTimerID;
- static UINT m_nMaxTooltipLength;
- static const UINT m_nTaskbarCreatedMsg;
- static CTrayWnd m_wndInvisible;
- static BOOL m_bShowWndAnimation;
- static BOOL GetW2K();
- #ifndef _WIN32_WCE
- static void GetTrayWndRect(LPRECT lprect);
- static BOOL GetDoWndAnimation();
- #endif
- // Generated message map functions
- protected:
- //{{AFX_MSG(CSystemTray)
- afx_msg void OnTimer(UINT_PTR nIDEvent);
- //}}AFX_MSG
- #ifndef _WIN32_WCE
- afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection);
- #endif
- LRESULT OnTaskbarCreated(WPARAM wParam, LPARAM lParam);
- DECLARE_MESSAGE_MAP()
- };
- #endif
- /////////////////////////////////////////////////////////////////////////////
|