systray.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <precomp.h>
  2. #ifdef WIN32
  3. #include <windows.h>
  4. #include <shellapi.h>
  5. #endif
  6. #include "systray.h"
  7. #include <bfc/assert.h>
  8. #include <bfc/wasabi_std.h>
  9. Systray::Systray(HWND wnd, int uid, int msg, HICON smallicon)
  10. {
  11. id = uid;
  12. hwnd = wnd;
  13. message = msg;
  14. icon = smallicon;
  15. /*int r = */addIcon();
  16. // always asserts with desktop with no systray support (litestep, WINE, etc...)
  17. // ASSERT(r == TRUE);
  18. }
  19. Systray::~Systray()
  20. {
  21. /*int r = */deleteIcon();
  22. // always asserts with desktop with no systray support (litestep, WINE, etc...)
  23. // ASSERT(r == TRUE);
  24. }
  25. void Systray::setTip(const wchar_t *_tip)
  26. {
  27. tip = _tip;
  28. tip.trunc(64);
  29. if (!tip.isempty())
  30. {
  31. /*int r = */setTip();
  32. // always asserts with desktop with no systray support (litestep, WINE, etc...)
  33. // ASSERT(r == TRUE);
  34. }
  35. }
  36. bool Systray::addIcon()
  37. {
  38. #ifdef WIN32
  39. NOTIFYICONDATAW tnid = {0};
  40. tnid.cbSize = sizeof(NOTIFYICONDATAW);
  41. tnid.uID = id;
  42. tnid.hWnd = hwnd;
  43. tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
  44. tnid.uCallbackMessage = message;
  45. tnid.hIcon = icon;
  46. if (tip)
  47. WCSCPYN(tnid.szTip, tip, sizeof(tnid.szTip)/sizeof(wchar_t));
  48. return !!Shell_NotifyIconW(NIM_ADD, &tnid);
  49. #else
  50. DebugString("portme Systray::addIcon\n");
  51. return 1;
  52. #endif
  53. }
  54. bool Systray::setTip()
  55. {
  56. #ifdef WIN32
  57. NOTIFYICONDATAW tnid = {0};
  58. tnid.cbSize = sizeof(NOTIFYICONDATAW);
  59. tnid.uFlags = NIF_TIP;
  60. tnid.uID = id;
  61. tnid.hWnd = hwnd;
  62. if (tip)
  63. WCSCPYN(tnid.szTip, tip, sizeof(tnid.szTip)/sizeof(wchar_t));
  64. return !!Shell_NotifyIconW(NIM_MODIFY, &tnid);
  65. #else
  66. DebugString("portme Systray::setTip\n");
  67. return 1;
  68. #endif
  69. }
  70. bool Systray::deleteIcon()
  71. {
  72. #ifdef WIN32
  73. NOTIFYICONDATA tnid = {0};
  74. tnid.cbSize = sizeof(NOTIFYICONDATAW);
  75. tnid.hWnd = hwnd;
  76. tnid.uID = id;
  77. return !!Shell_NotifyIcon(NIM_DELETE, &tnid);
  78. #else
  79. DebugString("portme Systray::deleteIcon\n");
  80. return 1;
  81. #endif
  82. }