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
[] = {'C','P','U',' ','U','s','a','g','e',':',' ','%','d','%','%',0};
147 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
149 hIcon
= TrayIcon_GetProcessorUsageIcon();
151 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
154 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
155 nid
.uCallbackMessage
= WM_ONTRAYICON
;
157 wsprintfW(nid
.szTip
, wszCPU_Usage
, PerfDataGetProcessorUsage());
159 bRetVal
= Shell_NotifyIconW(NIM_ADD
, &nid
);
167 BOOL
TrayIcon_ShellRemoveTrayIcon(void)
172 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
174 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
178 nid
.uCallbackMessage
= WM_ONTRAYICON
;
180 bRetVal
= Shell_NotifyIconW(NIM_DELETE
, &nid
);
185 BOOL
TrayIcon_ShellUpdateTrayIcon(void)
190 WCHAR wszCPU_Usage
[] = {'C','P','U',' ','U','s','a','g','e',':',' ','%','d','%','%',0};
192 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
194 hIcon
= TrayIcon_GetProcessorUsageIcon();
196 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
199 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
200 nid
.uCallbackMessage
= WM_ONTRAYICON
;
202 wsprintfW(nid
.szTip
, wszCPU_Usage
, PerfDataGetProcessorUsage());
204 bRetVal
= Shell_NotifyIconW(NIM_MODIFY
, &nid
);