You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TrayIcon.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. // -=- CView.h
  19. // An instance of the CView class is created for each VNC Viewer connection.
  20. #ifndef __RFB_WIN32_TRAY_ICON_H__
  21. #define __RFB_WIN32_TRAY_ICON_H__
  22. #define WIN32_LEAN_AND_MEAN
  23. #include <windows.h>
  24. #include <shellapi.h>
  25. #include <rfb_win32/MsgWindow.h>
  26. #include <rdr/Exception.h>
  27. namespace rfb {
  28. namespace win32 {
  29. class TrayIcon : public MsgWindow {
  30. public:
  31. TrayIcon() : MsgWindow(_T("VNCTray")) {
  32. #ifdef NOTIFYICONDATA_V1_SIZE
  33. nid.cbSize = NOTIFYICONDATA_V1_SIZE;
  34. #else
  35. nid.cbSize = sizeof(NOTIFYICONDATA);
  36. #endif
  37. nid.hWnd = getHandle();
  38. nid.uID = 0;
  39. nid.hIcon = 0;
  40. nid.uFlags = NIF_ICON | NIF_MESSAGE;
  41. nid.uCallbackMessage = WM_USER;
  42. }
  43. virtual ~TrayIcon() {
  44. remove();
  45. }
  46. bool setIcon(UINT icon) {
  47. if (icon == 0) {
  48. return remove();
  49. } else {
  50. nid.hIcon = (HICON)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(icon),
  51. IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
  52. return refresh();
  53. }
  54. }
  55. bool setToolTip(const TCHAR* text) {
  56. if (text == 0) {
  57. nid.uFlags &= ~NIF_TIP;
  58. } else {
  59. const int tipLen = sizeof(nid.szTip)/sizeof(TCHAR);
  60. _tcsncpy(nid.szTip, text, tipLen);
  61. nid.szTip[tipLen-1] = 0;
  62. nid.uFlags |= NIF_TIP;
  63. }
  64. return refresh();
  65. }
  66. bool remove() {
  67. return Shell_NotifyIcon(NIM_DELETE, &nid) != 0;
  68. }
  69. bool refresh() {
  70. return Shell_NotifyIcon(NIM_MODIFY, &nid) || Shell_NotifyIcon(NIM_ADD, &nid);
  71. }
  72. protected:
  73. NOTIFYICONDATA nid;
  74. };
  75. };
  76. };
  77. #endif