6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
42 HICON
TrayIcon_GetProcessorUsageIcon(void)
44 HICON hTrayIcon
= NULL
;
47 HBITMAP hBitmap
= NULL
;
48 HBITMAP hOldBitmap
= NULL
;
49 HBITMAP hBitmapMask
= NULL
;
53 HBRUSH hBitmapBrush
= NULL
;
57 // Get a handle to the screen DC
59 hScreenDC
= GetDC(NULL
);
64 // Create our own DC from it
66 hDC
= CreateCompatibleDC(hScreenDC
);
73 hBitmap
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_TRAYICON
));
74 hBitmapMask
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_TRAYMASK
));
75 if (!hBitmap
|| !hBitmapMask
)
78 hBitmapBrush
= CreateSolidBrush(RGB(0, 255, 0));
83 // Select the bitmap into our device context
84 // so we can draw on it.
86 hOldBitmap
= (HBITMAP
) SelectObject(hDC
, hBitmap
);
91 ProcessorUsage
= PerfDataGetProcessorUsage();
94 // Calculate how many lines to draw
95 // since we have 11 rows of space
96 // to draw the cpu usage instead of
99 nLinesToDraw
= (ProcessorUsage
+ (ProcessorUsage
/ 10)) / 11;
101 rc
.top
= 12 - nLinesToDraw
;
106 // Now draw the cpu usage
109 FillRect(hDC
, &rc
, hBitmapBrush
);
112 // Now that we are done drawing put the
115 SelectObject(hDC
, hOldBitmap
);
118 iconInfo
.fIcon
= TRUE
;
119 iconInfo
.xHotspot
= 0;
120 iconInfo
.yHotspot
= 0;
121 iconInfo
.hbmMask
= hBitmapMask
;
122 iconInfo
.hbmColor
= hBitmap
;
124 hTrayIcon
= CreateIconIndirect(&iconInfo
);
131 ReleaseDC(NULL
, hScreenDC
);
133 SelectObject(hDC
, hOldBitmap
);
137 DeleteObject(hBitmapBrush
);
139 DeleteObject(hBitmap
);
141 DeleteObject(hBitmapMask
);
144 // Return the newly created tray icon (if successful)
149 BOOL
TrayIcon_ShellAddTrayIcon(void)
155 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
157 hIcon
= TrayIcon_GetProcessorUsageIcon();
159 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
162 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
163 //nid.uCallbackMessage = ??;
165 sprintf(nid
.szTip
, "CPU Usage: %d%%", PerfDataGetProcessorUsage());
167 bRetVal
= Shell_NotifyIcon(NIM_ADD
, &nid
);
175 BOOL
TrayIcon_ShellRemoveTrayIcon(void)
180 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
182 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
186 //nid.uCallbackMessage = ??;
188 bRetVal
= Shell_NotifyIcon(NIM_DELETE
, &nid
);
193 BOOL
TrayIcon_ShellUpdateTrayIcon(void)
199 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
201 hIcon
= TrayIcon_GetProcessorUsageIcon();
203 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
206 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
207 //nid.uCallbackMessage = ??;
209 sprintf(nid
.szTip
, "CPU Usage: %d%%", PerfDataGetProcessorUsage());
211 bRetVal
= Shell_NotifyIcon(NIM_MODIFY
, &nid
);