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