6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
32 #include "wine/unicode.h"
36 static HICON TrayIcon_GetProcessorUsageIcon(void)
38 HICON hTrayIcon = NULL;
41 HBITMAP hBitmap = NULL;
43 HBITMAP hBitmapMask = NULL;
47 HBRUSH hBitmapBrush = NULL;
51 * Get a handle to the screen DC
53 hScreenDC = GetDC(NULL);
58 * Create our own DC from it
60 hDC = CreateCompatibleDC(hScreenDC);
67 hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TRAYICON));
68 hBitmapMask = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TRAYMASK));
69 if (!hBitmap || !hBitmapMask)
72 hBitmapBrush = CreateSolidBrush(RGB(0, 255, 0));
77 * Select the bitmap into our device context
78 * so we can draw on it.
80 hOldBitmap = SelectObject(hDC, hBitmap);
85 ProcessorUsage = PerfDataGetProcessorUsage();
88 * Calculate how many lines to draw
89 * since we have 11 rows of space
90 * to draw the cpu usage instead of
93 nLinesToDraw = (ProcessorUsage + (ProcessorUsage / 10)) / 11;
95 rc.top = 12 - nLinesToDraw;
100 * Now draw the cpu usage
103 FillRect(hDC, &rc, hBitmapBrush);
106 * Now that we are done drawing put the
109 SelectObject(hDC, hOldBitmap);
111 iconInfo.fIcon = TRUE;
112 iconInfo.xHotspot = 0;
113 iconInfo.yHotspot = 0;
114 iconInfo.hbmMask = hBitmapMask;
115 iconInfo.hbmColor = hBitmap;
117 hTrayIcon = CreateIconIndirect(&iconInfo);
124 ReleaseDC(NULL, hScreenDC);
128 DeleteObject(hBitmapBrush);
130 DeleteObject(hBitmap);
132 DeleteObject(hBitmapMask);
135 * Return the newly created tray icon (if successful)
140 BOOL TrayIcon_ShellAddTrayIcon(void)
145 WCHAR wszCPU_Usage[255];
147 LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR));
149 memset(&nid, 0, sizeof(NOTIFYICONDATAW));
151 hIcon = TrayIcon_GetProcessorUsageIcon();
153 nid.cbSize = sizeof(NOTIFYICONDATAW);
156 nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
157 nid.uCallbackMessage = WM_ONTRAYICON;
159 wsprintfW(nid.szTip, wszCPU_Usage, PerfDataGetProcessorUsage());
161 bRetVal = Shell_NotifyIconW(NIM_ADD, &nid);
169 BOOL TrayIcon_ShellRemoveTrayIcon(void)
174 memset(&nid, 0, sizeof(NOTIFYICONDATAW));
176 nid.cbSize = sizeof(NOTIFYICONDATAW);
180 nid.uCallbackMessage = WM_ONTRAYICON;
182 bRetVal = Shell_NotifyIconW(NIM_DELETE, &nid);
187 BOOL TrayIcon_ShellUpdateTrayIcon(void)
192 WCHAR wszCPU_Usage[255];
194 LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR));
196 memset(&nid, 0, sizeof(NOTIFYICONDATAW));
198 hIcon = TrayIcon_GetProcessorUsageIcon();
200 nid.cbSize = sizeof(NOTIFYICONDATAW);
203 nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
204 nid.uCallbackMessage = WM_ONTRAYICON;
206 wsprintfW(nid.szTip, wszCPU_Usage, PerfDataGetProcessorUsage());
208 bRetVal = Shell_NotifyIconW(NIM_MODIFY, &nid);