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
31 #include "wine/unicode.h"
35 static HICON
TrayIcon_GetProcessorUsageIcon(void)
37 HICON hTrayIcon
= NULL
;
40 HBITMAP hBitmap
= NULL
;
42 HBITMAP hBitmapMask
= NULL
;
46 HBRUSH hBitmapBrush
= NULL
;
50 * Get a handle to the screen DC
52 hScreenDC
= GetDC(NULL
);
57 * Create our own DC from it
59 hDC
= CreateCompatibleDC(hScreenDC
);
66 hBitmap
= LoadBitmapW(hInst
, MAKEINTRESOURCEW(IDB_TRAYICON
));
67 hBitmapMask
= LoadBitmapW(hInst
, MAKEINTRESOURCEW(IDB_TRAYMASK
));
68 if (!hBitmap
|| !hBitmapMask
)
71 hBitmapBrush
= CreateSolidBrush(RGB(0, 255, 0));
76 * Select the bitmap into our device context
77 * so we can draw on it.
79 hOldBitmap
= SelectObject(hDC
, hBitmap
);
84 ProcessorUsage
= PerfDataGetProcessorUsage();
87 * Calculate how many lines to draw
88 * since we have 11 rows of space
89 * to draw the cpu usage instead of
92 nLinesToDraw
= (ProcessorUsage
+ (ProcessorUsage
/ 10)) / 11;
94 rc
.top
= 12 - nLinesToDraw
;
99 * Now draw the cpu usage
102 FillRect(hDC
, &rc
, hBitmapBrush
);
105 * Now that we are done drawing put the
108 SelectObject(hDC
, hOldBitmap
);
110 iconInfo
.fIcon
= TRUE
;
111 iconInfo
.xHotspot
= 0;
112 iconInfo
.yHotspot
= 0;
113 iconInfo
.hbmMask
= hBitmapMask
;
114 iconInfo
.hbmColor
= hBitmap
;
116 hTrayIcon
= CreateIconIndirect(&iconInfo
);
123 ReleaseDC(NULL
, hScreenDC
);
127 DeleteObject(hBitmapBrush
);
129 DeleteObject(hBitmap
);
131 DeleteObject(hBitmapMask
);
134 * Return the newly created tray icon (if successful)
139 BOOL
TrayIcon_ShellAddTrayIcon(void)
144 WCHAR wszCPU_Usage
[255];
146 LoadStringW(hInst
, IDS_STATUS_BAR_CPU_USAGE
, wszCPU_Usage
, sizeof(wszCPU_Usage
)/sizeof(WCHAR
));
148 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
150 hIcon
= TrayIcon_GetProcessorUsageIcon();
152 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
155 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
156 nid
.uCallbackMessage
= WM_ONTRAYICON
;
158 wsprintfW(nid
.szTip
, wszCPU_Usage
, PerfDataGetProcessorUsage());
160 bRetVal
= Shell_NotifyIconW(NIM_ADD
, &nid
);
168 BOOL
TrayIcon_ShellRemoveTrayIcon(void)
173 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
175 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
179 nid
.uCallbackMessage
= WM_ONTRAYICON
;
181 bRetVal
= Shell_NotifyIconW(NIM_DELETE
, &nid
);
186 BOOL
TrayIcon_ShellUpdateTrayIcon(void)
191 WCHAR wszCPU_Usage
[255];
193 LoadStringW(hInst
, IDS_STATUS_BAR_CPU_USAGE
, wszCPU_Usage
, sizeof(wszCPU_Usage
)/sizeof(WCHAR
));
195 memset(&nid
, 0, sizeof(NOTIFYICONDATAW
));
197 hIcon
= TrayIcon_GetProcessorUsageIcon();
199 nid
.cbSize
= sizeof(NOTIFYICONDATAW
);
202 nid
.uFlags
= NIF_ICON
| NIF_MESSAGE
| NIF_TIP
;
203 nid
.uCallbackMessage
= WM_ONTRAYICON
;
205 wsprintfW(nid
.szTip
, wszCPU_Usage
, PerfDataGetProcessorUsage());
207 bRetVal
= Shell_NotifyIconW(NIM_MODIFY
, &nid
);