6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * 2005 Klemens Friedl <frik85@reactos.at>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 HICON
TrayIcon_GetProcessorUsageIcon(void)
28 HICON hTrayIcon
= NULL
;
31 HBITMAP hBitmap
= NULL
;
32 HBITMAP hOldBitmap
= NULL
;
33 HBITMAP hBitmapMask
= NULL
;
37 HBRUSH hBitmapBrush
= NULL
;
41 * Get a handle to the screen DC
43 hScreenDC
= GetDC(NULL
);
48 * Create our own DC from it
50 hDC
= CreateCompatibleDC(hScreenDC
);
57 hBitmap
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_TRAYICON
));
58 hBitmapMask
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_TRAYMASK
));
59 if (!hBitmap
|| !hBitmapMask
)
62 hBitmapBrush
= CreateSolidBrush(RGB(0, 255, 0));
67 * Select the bitmap into our device context
68 * so we can draw on it.
70 hOldBitmap
= (HBITMAP
) SelectObject(hDC
, hBitmap
);
75 ProcessorUsage
= PerfDataGetProcessorUsage();
78 * Calculate how many lines to draw
79 * since we have 11 rows of space
80 * to draw the cpu usage instead of
83 nLinesToDraw
= (ProcessorUsage
+ (ProcessorUsage
/ 10)) / 11;
85 rc
.top
= 12 - nLinesToDraw
;
90 * Now draw the cpu usage
93 FillRect(hDC
, &rc
, hBitmapBrush
);
96 * Now that we are done drawing put the
99 SelectObject(hDC
, hOldBitmap
);
102 iconInfo
.fIcon
= TRUE
;
103 iconInfo
.xHotspot
= 0;
104 iconInfo
.yHotspot
= 0;
105 iconInfo
.hbmMask
= hBitmapMask
;
106 iconInfo
.hbmColor
= hBitmap
;
108 hTrayIcon
= CreateIconIndirect(&iconInfo
);
115 ReleaseDC(NULL
, hScreenDC
);
117 SelectObject(hDC
, hOldBitmap
);
121 DeleteObject(hBitmapBrush
);
123 DeleteObject(hBitmap
);
125 DeleteObject(hBitmapMask
);
128 * Return the newly created tray icon (if successful)
133 BOOL
TrayIcon_ShellAddTrayIcon(void)
139 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
141 hIcon
= TrayIcon_GetProcessorUsageIcon();
143 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
146 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
147 nid
.uCallbackMessage
= WM_ONTRAYICON
;
149 wsprintf(nid
.szTip
, _T("CPU Usage: %d%%"), PerfDataGetProcessorUsage());
151 bRetVal
= Shell_NotifyIcon(NIM_ADD
, &nid
);
159 BOOL
TrayIcon_ShellRemoveTrayIcon(void)
164 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
166 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
170 nid
.uCallbackMessage
= WM_ONTRAYICON
;
172 bRetVal
= Shell_NotifyIcon(NIM_DELETE
, &nid
);
177 BOOL
TrayIcon_ShellUpdateTrayIcon(void)
184 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
186 hIcon
= TrayIcon_GetProcessorUsageIcon();
188 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
191 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
192 nid
.uCallbackMessage
= WM_ONTRAYICON
;
194 LoadString(hInst
, IDS_MSG_TRAYICONCPUUSAGE
, szTemp
, 256);
195 wsprintf(nid
.szTip
, szTemp
, PerfDataGetProcessorUsage());
197 bRetVal
= Shell_NotifyIcon(NIM_MODIFY
, &nid
);