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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright (C) 2002-2005 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. #include <windows.h>
  23. #include <shellapi.h>
  24. #include <rfb_win32/MsgWindow.h>
  25. #include <rdr/Exception.h>
  26. namespace rfb {
  27. namespace win32 {
  28. class TrayIcon : public MsgWindow {
  29. public:
  30. TrayIcon() : MsgWindow(_T("VNCTray")) {
  31. #ifdef NOTIFYICONDATA_V1_SIZE
  32. nid.cbSize = NOTIFYICONDATA_V1_SIZE;
  33. #else
  34. nid.cbSize = sizeof(NOTIFYICONDATA);
  35. #endif
  36. nid.hWnd = getHandle();
  37. nid.uID = 0;
  38. nid.hIcon = 0;
  39. nid.uFlags = NIF_ICON | NIF_MESSAGE;
  40. nid.uCallbackMessage = WM_USER;
  41. }
  42. virtual ~TrayIcon() {
  43. remove();
  44. }
  45. bool setIcon(UINT icon) {
  46. if (icon == 0) {
  47. return remove();
  48. } else {
  49. nid.hIcon = (HICON)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(icon),
  50. IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
  51. return refresh();
  52. }
  53. }
  54. bool setToolTip(const TCHAR* text) {
  55. if (text == 0) {
  56. nid.uFlags &= ~NIF_TIP;
  57. } else {
  58. const int tipLen = sizeof(nid.szTip)/sizeof(TCHAR);
  59. _tcsncpy(nid.szTip, text, tipLen);
  60. nid.szTip[tipLen-1] = 0;
  61. nid.uFlags |= NIF_TIP;
  62. }
  63. return refresh();
  64. }
  65. bool remove() {
  66. return Shell_NotifyIcon(NIM_DELETE, &nid) != 0;
  67. }
  68. bool refresh() {
  69. return Shell_NotifyIcon(NIM_MODIFY, &nid) || Shell_NotifyIcon(NIM_ADD, &nid);
  70. }
  71. protected:
  72. NOTIFYICONDATA nid;
  73. };
  74. };
  75. };
  76. #endif