TrayIcon.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef _ZEROT_TRAYICON_H
  2. #define _ZEROT_TRAYICON_H
  3. ////////////////
  4. #define MYWM_SHOWMINBOX WM_USER + 2 // 自定义消息,显示迷你对话框;
  5. class ITrayIcon : public CCmdTarget
  6. {
  7. protected:
  8. DECLARE_DYNAMIC(ITrayIcon)
  9. NOTIFYICONDATA m_nid; // struct for Shell_NotifyIcon args
  10. public:
  11. ITrayIcon(UINT uID);
  12. ~ITrayIcon();
  13. // Call this to receive tray notifications
  14. void SetNotificationWnd(CWnd* pNotifyWnd, UINT uCbMsg);
  15. // SetIcon functions. To remove icon, call SetIcon(0)
  16. BOOL SetIcon(UINT uID); // only set the icon,but without tip zt.
  17. BOOL SetIcon(HICON hicon, LPCTSTR lpTip);
  18. BOOL SetIcon(UINT uID, LPCTSTR lpTip);
  19. BOOL SetIcon(LPCTSTR lpResName, LPCTSTR lpTip)
  20. {
  21. return SetIcon(lpResName ? AfxGetApp()->LoadIcon(lpResName) : NULL, lpTip);
  22. }
  23. // 设置提示(设置提示时,是否也要同时设置图标???);
  24. BOOL SetTip(LPCTSTR lpTip);
  25. //BOOL SetInfo(LPCSTR lpInfo,LPCSTR lpInfoTitle = _T("")); // NIF_INFO
  26. BOOL SetInfo(LPCTSTR lpInfo,LPCTSTR lpInfoTitle = NULL); // NIF_INFO
  27. BOOL SetStandardIcon(LPCTSTR lpszIconName, LPCTSTR lpTip)
  28. {
  29. return SetIcon(::LoadIcon(NULL, lpszIconName), lpTip);
  30. }
  31. virtual LRESULT OnTrayNotification(WPARAM uID, LPARAM lEvent);
  32. // -------------------------------以下是托盘闪烁实现------------------------------- [5/30/2013 Z.t]
  33. public:
  34. bool IsFlashing(){return bSuspending;} // 外部调用,判断是否在闪烁;
  35. void SetMiniShow(BOOL bSet){bShowMinibox = bSet;}
  36. BOOL StartFlashing();
  37. BOOL StopFlashing();
  38. inline void SetIconInfos(const UINT &u1,const UINT &u2,const UINT &u3);
  39. inline void SetDefaultTip(LPCTSTR lpTip){_lpTip=lpTip;}
  40. protected:
  41. bool bSuspending; // 线程运行标识;
  42. LPCTSTR _lpTip; // 默认的提示;
  43. UINT _utIcon[3]; // 1.停止闪烁时的默认图标;2.闪烁时的报警图标;3.闪烁时的盘里背景图标;
  44. DWORD m_dwThreadID; // 线程ID;
  45. HANDLE m_hThreadCtrl; // 线程控件事件;
  46. HANDLE m_hThreadObj; // 线程本身;
  47. BOOL bShowMinibox; // 闪烁期间,是否对窗口发送消息;
  48. void GetTrayRect(RECT &rc);
  49. BOOL IsWow64();
  50. // 托盘闪烁线程;
  51. int OpendThread();
  52. void TerminalThread();
  53. static DWORD WINAPI FlashingThread(LPVOID pVoid);
  54. };
  55. inline void ITrayIcon::SetIconInfos(const UINT &u1,const UINT &u2,const UINT &u3)
  56. {
  57. _utIcon[0] = u1;
  58. _utIcon[1] = u2;
  59. _utIcon[2] = u3;
  60. }
  61. #endif
  62. // 未处理的BUG:
  63. // 1.在任务管理器中结束进程,托盘图标未能清除;
  64. // SetIcon(0)代表着清除托盘图标(NIF_DELETE);