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 */
37 HICON
TrayIcon_GetProcessorUsageIcon(void)
39 HICON hTrayIcon
= NULL
;
42 HBITMAP hBitmap
= NULL
;
44 HBITMAP hBitmapMask
= NULL
;
48 HBRUSH hBitmapBrush
= NULL
;
52 * Get a handle to the screen DC
54 hScreenDC
= GetDC(NULL
);
59 * Create our own DC from it
61 hDC
= CreateCompatibleDC(hScreenDC
);
68 hBitmap
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_TRAYICON
));
69 hBitmapMask
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_TRAYMASK
));
70 if (!hBitmap
|| !hBitmapMask
)
73 hBitmapBrush
= CreateSolidBrush(RGB(0, 255, 0));
78 * Select the bitmap into our device context
79 * so we can draw on it.
81 hOldBitmap
= (HBITMAP
) SelectObject(hDC
, hBitmap
);
86 ProcessorUsage
= PerfDataGetProcessorUsage();
89 * Calculate how many lines to draw
90 * since we have 11 rows of space
91 * to draw the cpu usage instead of
94 nLinesToDraw
= (ProcessorUsage
+ (ProcessorUsage
/ 10)) / 11;
96 rc
.top
= 12 - nLinesToDraw
;
101 * Now draw the cpu usage
104 FillRect(hDC
, &rc
, hBitmapBrush
);
107 * Now that we are done drawing put the
110 SelectObject(hDC
, hOldBitmap
);
112 iconInfo
.fIcon
= TRUE
;
113 iconInfo
.xHotspot
= 0;
114 iconInfo
.yHotspot
= 0;
115 iconInfo
.hbmMask
= hBitmapMask
;
116 iconInfo
.hbmColor
= hBitmap
;
118 hTrayIcon
= CreateIconIndirect(&iconInfo
);
125 ReleaseDC(NULL
, hScreenDC
);
129 DeleteObject(hBitmapBrush
);
131 DeleteObject(hBitmap
);
133 DeleteObject(hBitmapMask
);
136 * Return the newly created tray icon (if successful)
141 BOOL
TrayIcon_ShellAddTrayIcon(void)
147 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
149 hIcon
= TrayIcon_GetProcessorUsageIcon();
151 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
154 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
155 nid
.uCallbackMessage
= WM_ONTRAYICON
;
157 wsprintf(nid
.szTip
, _T("CPU Usage: %d%%"), PerfDataGetProcessorUsage());
159 bRetVal
= Shell_NotifyIcon(NIM_ADD
, &nid
);
167 BOOL
TrayIcon_ShellRemoveTrayIcon(void)
172 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
174 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
178 nid
.uCallbackMessage
= WM_ONTRAYICON
;
180 bRetVal
= Shell_NotifyIcon(NIM_DELETE
, &nid
);
185 BOOL
TrayIcon_ShellUpdateTrayIcon(void)
191 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
193 hIcon
= TrayIcon_GetProcessorUsageIcon();
195 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
198 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
199 nid
.uCallbackMessage
= WM_ONTRAYICON
;
201 wsprintf(nid
.szTip
, _T("CPU Usage: %d%%"), PerfDataGetProcessorUsage());
203 bRetVal
= Shell_NotifyIcon(NIM_MODIFY
, &nid
);