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
34 static HICON
TrayIcon_GetProcessorUsageIcon(void)
36 HICON hTrayIcon
= NULL
;
39 HBITMAP hBitmap
= NULL
;
41 HBITMAP hBitmapMask
= NULL
;
45 HBRUSH hBitmapBrush
= NULL
;
49 * Get a handle to the screen DC
51 hScreenDC
= GetDC(NULL
);
56 * Create our own DC from it
58 hDC
= CreateCompatibleDC(hScreenDC
);
65 hBitmap
= LoadBitmapW(hInst
, MAKEINTRESOURCEW(IDB_TRAYICON
));
66 hBitmapMask
= LoadBitmapW(hInst
, MAKEINTRESOURCEW(IDB_TRAYMASK
));
67 if (!hBitmap
|| !hBitmapMask
)
70 hBitmapBrush
= CreateSolidBrush(RGB(0, 255, 0));
75 * Select the bitmap into our device context
76 * so we can draw on it.
78 hOldBitmap
= SelectObject(hDC
, hBitmap
);
83 ProcessorUsage
= PerfDataGetProcessorUsage();
86 * Calculate how many lines to draw
87 * since we have 11 rows of space
88 * to draw the cpu usage instead of
91 nLinesToDraw
= (ProcessorUsage
+ (ProcessorUsage
/ 10)) / 11;
92 SetRect(&rc
, 3, 12 - nLinesToDraw
, 13, 13);
95 * Now draw the cpu usage
98 FillRect(hDC
, &rc
, hBitmapBrush
);
101 * Now that we are done drawing put the
104 SelectObject(hDC
, hOldBitmap
);
106 iconInfo
.fIcon
= TRUE
;
107 iconInfo
.xHotspot
= 0;
108 iconInfo
.yHotspot
= 0;
109 iconInfo
.hbmMask
= hBitmapMask
;
110 iconInfo
.hbmColor
= hBitmap
;
112 hTrayIcon
= CreateIconIndirect(&iconInfo
);
119 ReleaseDC(NULL
, hScreenDC
);
123 DeleteObject(hBitmapBrush
);
125 DeleteObject(hBitmap
);
127 DeleteObject(hBitmapMask
);
130 * Return the newly created tray icon (if successful)
135 BOOL
TrayIcon_ShellAddTrayIcon(void)
140 WCHAR wszCPU_Usage
[255];
142 LoadStringW(hInst
, IDS_STATUS_BAR_CPU_USAGE
, wszCPU_Usage
, ARRAY_SIZE(wszCPU_Usage
));
144 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
146 hIcon
= TrayIcon_GetProcessorUsageIcon();
148 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
151 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
152 nid
.uCallbackMessage
= WM_ONTRAYICON
;
154 wsprintfW(nid
.szTip
, wszCPU_Usage
, PerfDataGetProcessorUsage());
156 bRetVal
= Shell_NotifyIconW(NIM_ADD
, &nid
);
164 BOOL
TrayIcon_ShellRemoveTrayIcon(void)
169 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
171 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
175 nid
.uCallbackMessage
= WM_ONTRAYICON
;
177 bRetVal
= Shell_NotifyIconW(NIM_DELETE
, &nid
);
182 BOOL
TrayIcon_ShellUpdateTrayIcon(void)
187 WCHAR wszCPU_Usage
[255];
189 LoadStringW(hInst
, IDS_STATUS_BAR_CPU_USAGE
, wszCPU_Usage
, ARRAY_SIZE(wszCPU_Usage
));
191 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
193 hIcon
= TrayIcon_GetProcessorUsageIcon();
195 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
198 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
199 nid
.uCallbackMessage
= WM_ONTRAYICON
;
201 wsprintfW(nid
.szTip
, wszCPU_Usage
, PerfDataGetProcessorUsage());
203 bRetVal
= Shell_NotifyIconW(NIM_MODIFY
, &nid
);