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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
= LoadBitmapW(hInst
, MAKEINTRESOURCEW(IDB_TRAYICON
));
58 hBitmapMask
= LoadBitmapW(hInst
, MAKEINTRESOURCEW(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 hBitmap
= SelectObject(hDC
, hOldBitmap
);
102 iconInfo
.fIcon
= TRUE
;
103 iconInfo
.hbmMask
= hBitmapMask
;
104 iconInfo
.hbmColor
= hBitmap
;
106 hTrayIcon
= CreateIconIndirect(&iconInfo
);
113 ReleaseDC(NULL
, hScreenDC
);
117 DeleteObject(hBitmapBrush
);
119 DeleteObject(hBitmap
);
121 DeleteObject(hBitmapMask
);
124 * Return the newly created tray icon (if successful)
129 BOOL
TrayIcon_ShellAddTrayIcon(void)
136 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
138 hIcon
= TrayIcon_GetProcessorUsageIcon();
140 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
143 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
144 nid
.uCallbackMessage
= WM_ONTRAYICON
;
148 LoadStringW( GetModuleHandleW(NULL
), IDS_MSG_TRAYICONCPUUSAGE
, szMsg
, sizeof(szMsg
) / sizeof(szMsg
[0]));
149 wsprintfW(nid
.szTip
, szMsg
, PerfDataGetProcessorUsage());
151 bRetVal
= Shell_NotifyIconW(NIM_ADD
, &nid
);
159 BOOL
TrayIcon_ShellRemoveTrayIcon(void)
164 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
166 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
170 nid
.uCallbackMessage
= WM_ONTRAYICON
;
172 bRetVal
= Shell_NotifyIconW(NIM_DELETE
, &nid
);
177 BOOL
TrayIcon_ShellUpdateTrayIcon(void)
184 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
186 hIcon
= TrayIcon_GetProcessorUsageIcon();
188 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
191 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
192 nid
.uCallbackMessage
= WM_ONTRAYICON
;
194 LoadStringW(hInst
, IDS_MSG_TRAYICONCPUUSAGE
, szTemp
, sizeof(szTemp
)/sizeof(szTemp
[0]));
195 wsprintfW(nid
.szTip
, szTemp
, PerfDataGetProcessorUsage());
197 bRetVal
= Shell_NotifyIconW(NIM_MODIFY
, &nid
);