ItrayIcon.h 2.6 KB

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