Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame^] | 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 | |
| 19 | // -=- CView.h |
| 20 | |
| 21 | // An instance of the CView class is created for each VNC Viewer connection. |
| 22 | |
| 23 | #ifndef __RFB_WIN32_TRAY_ICON_H__ |
| 24 | #define __RFB_WIN32_TRAY_ICON_H__ |
| 25 | |
| 26 | #include <windows.h> |
| 27 | #include <shellapi.h> |
| 28 | #include <rfb_win32/MsgWindow.h> |
| 29 | #include <rdr/Exception.h> |
| 30 | |
| 31 | namespace rfb { |
| 32 | |
| 33 | namespace win32 { |
| 34 | |
| 35 | class TrayIcon : public MsgWindow { |
| 36 | public: |
| 37 | TrayIcon() : MsgWindow(_T("VNCTray")) { |
| 38 | #ifdef NOTIFYICONDATA_V1_SIZE |
| 39 | nid.cbSize = NOTIFYICONDATA_V1_SIZE; |
| 40 | #else |
| 41 | nid.cbSize = sizeof(NOTIFYICONDATA); |
| 42 | #endif |
| 43 | |
| 44 | nid.hWnd = getHandle(); |
| 45 | nid.uID = 0; |
| 46 | nid.hIcon = 0; |
| 47 | nid.uFlags = NIF_ICON | NIF_MESSAGE; |
| 48 | nid.uCallbackMessage = WM_USER; |
| 49 | } |
| 50 | virtual ~TrayIcon() { |
| 51 | remove(); |
| 52 | } |
| 53 | bool setIcon(UINT icon) { |
| 54 | if (icon == 0) { |
| 55 | return remove(); |
| 56 | } else { |
| 57 | nid.hIcon = (HICON)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(icon), |
| 58 | IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED); |
| 59 | return refresh(); |
| 60 | } |
| 61 | } |
| 62 | bool setToolTip(const TCHAR* text) { |
| 63 | if (text == 0) { |
| 64 | nid.uFlags &= ~NIF_TIP; |
| 65 | } else { |
| 66 | const int tipLen = sizeof(nid.szTip)/sizeof(TCHAR); |
| 67 | _tcsncpy(nid.szTip, text, tipLen); |
| 68 | nid.szTip[tipLen-1] = 0; |
| 69 | nid.uFlags |= NIF_TIP; |
| 70 | } |
| 71 | return refresh(); |
| 72 | } |
| 73 | bool remove() { |
| 74 | return Shell_NotifyIcon(NIM_DELETE, &nid) != 0; |
| 75 | } |
| 76 | bool refresh() { |
| 77 | return Shell_NotifyIcon(NIM_MODIFY, &nid) || Shell_NotifyIcon(NIM_ADD, &nid); |
| 78 | } |
| 79 | protected: |
| 80 | NOTIFYICONDATA nid; |
| 81 | }; |
| 82 | |
| 83 | }; |
| 84 | |
| 85 | }; |
| 86 | |
| 87 | #endif |
| 88 | |
| 89 | |