ReactOS 0.4.15-dev-5666-gc548b97
trayicon.c
Go to the documentation of this file.
1/*
2 * ReactOS Task Manager
3 *
4 * trayicon.c
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * 2005 Klemens Friedl <frik85@reactos.at>
8 *
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.
13 *
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.
18 *
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
22 */
23
24#include "precomp.h"
25
27{
28 HICON hTrayIcon = NULL;
29 HDC hScreenDC = NULL;
30 HDC hDC = NULL;
32 HBITMAP hOldBitmap = NULL;
33 HBITMAP hBitmapMask = NULL;
34 ICONINFO iconInfo;
35 ULONG ProcessorUsage;
36 int nLinesToDraw;
37 HBRUSH hBitmapBrush = NULL;
38 RECT rc;
39
40 /*
41 * Get a handle to the screen DC
42 */
43 hScreenDC = GetDC(NULL);
44 if (!hScreenDC)
45 goto done;
46
47 /*
48 * Create our own DC from it
49 */
50 hDC = CreateCompatibleDC(hScreenDC);
51 if (!hDC)
52 goto done;
53
54 /*
55 * Load the bitmaps
56 */
59 if (!hBitmap || !hBitmapMask)
60 goto done;
61
62 hBitmapBrush = CreateSolidBrush(RGB(0, 255, 0));
63 if (!hBitmapBrush)
64 goto done;
65
66 /*
67 * Select the bitmap into our device context
68 * so we can draw on it.
69 */
70 hOldBitmap = (HBITMAP) SelectObject(hDC, hBitmap);
71
72 /*
73 * Get the cpu usage
74 */
75 ProcessorUsage = PerfDataGetProcessorUsage();
76
77 /*
78 * Calculate how many lines to draw
79 * since we have 11 rows of space
80 * to draw the cpu usage instead of
81 * just having 10.
82 */
83 nLinesToDraw = (ProcessorUsage + (ProcessorUsage / 10)) / 11;
84 rc.left = 3;
85 rc.top = 12 - nLinesToDraw;
86 rc.right = 13;
87 rc.bottom = 13;
88
89 /*
90 * Now draw the cpu usage
91 */
92 if (nLinesToDraw)
93 FillRect(hDC, &rc, hBitmapBrush);
94
95 /*
96 * Now that we are done drawing put the
97 * old bitmap back.
98 */
99 hBitmap = SelectObject(hDC, hOldBitmap);
100 hOldBitmap = NULL;
101
102 iconInfo.fIcon = TRUE;
103 iconInfo.hbmMask = hBitmapMask;
104 iconInfo.hbmColor = hBitmap;
105
106 hTrayIcon = CreateIconIndirect(&iconInfo);
107
108done:
109 /*
110 * Cleanup
111 */
112 if (hScreenDC)
113 ReleaseDC(NULL, hScreenDC);
114 if (hDC)
115 DeleteDC(hDC);
116 if (hBitmapBrush)
117 DeleteObject(hBitmapBrush);
118 if (hBitmap)
120 if (hBitmapMask)
121 DeleteObject(hBitmapMask);
122
123 /*
124 * Return the newly created tray icon (if successful)
125 */
126 return hTrayIcon;
127}
128
130{
132 HICON hIcon = NULL;
133 BOOL bRetVal;
134 WCHAR szMsg[64];
135
136 memset(&nid, 0, sizeof(NOTIFYICONDATAW));
137
139
140 nid.cbSize = sizeof(NOTIFYICONDATAW);
141 nid.hWnd = hMainWnd;
142 nid.uID = 0;
145 nid.hIcon = hIcon;
146
147
148 LoadStringW( GetModuleHandleW(NULL), IDS_MSG_TRAYICONCPUUSAGE, szMsg, sizeof(szMsg) / sizeof(szMsg[0]));
150
151 bRetVal = Shell_NotifyIconW(NIM_ADD, &nid);
152
153 if (hIcon)
155
156 return bRetVal;
157}
158
160{
162 BOOL bRetVal;
163
164 memset(&nid, 0, sizeof(NOTIFYICONDATAW));
165
166 nid.cbSize = sizeof(NOTIFYICONDATAW);
167 nid.hWnd = hMainWnd;
168 nid.uID = 0;
169 nid.uFlags = 0;
171
172 bRetVal = Shell_NotifyIconW(NIM_DELETE, &nid);
173
174 return bRetVal;
175}
176
178{
180 HICON hIcon = NULL;
181 BOOL bRetVal;
182 WCHAR szTemp[64];
183
184 memset(&nid, 0, sizeof(NOTIFYICONDATAW));
185
187
188 nid.cbSize = sizeof(NOTIFYICONDATAW);
189 nid.hWnd = hMainWnd;
190 nid.uID = 0;
193 nid.hIcon = hIcon;
194 LoadStringW(hInst, IDS_MSG_TRAYICONCPUUSAGE, szTemp, sizeof(szTemp)/sizeof(szTemp[0]));
196
197 bRetVal = Shell_NotifyIconW(NIM_MODIFY, &nid);
198
199 if (hIcon)
201
202 return bRetVal;
203}
static HDC hDC
Definition: 3dtext.c:33
#define IDB_TRAYMASK
Definition: resource.h:26
#define IDB_TRAYICON
Definition: resource.h:27
#define IDS_MSG_TRAYICONCPUUSAGE
Definition: resource.h:252
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
static HBITMAP hBitmap
Definition: timezone.c:26
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define RGB(r, g, b)
Definition: precomp.h:62
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
unsigned int ULONG
Definition: retypes.h:1
HWND hMainWnd
Definition: magnifier.c:32
NOTIFYICONDATA nid
Definition: magnifier.c:44
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
static HICON
Definition: imagelist.c:84
HICON hIcon
Definition: msconfig.c:44
ULONG PerfDataGetProcessorUsage(void)
Definition: perfdata.c:472
#define memset(x, y, z)
Definition: compat.h:39
struct _NOTIFYICONDATAW NOTIFYICONDATAW
#define NIM_DELETE
Definition: shellapi.h:93
#define NIM_MODIFY
Definition: shellapi.h:92
#define NIF_ICON
Definition: shellapi.h:103
#define NIF_MESSAGE
Definition: shellapi.h:102
#define NIM_ADD
Definition: shellapi.h:91
#define NIF_TIP
Definition: shellapi.h:104
BOOL fIcon
Definition: winuser.h:3113
HBITMAP hbmColor
Definition: winuser.h:3117
HBITMAP hbmMask
Definition: winuser.h:3116
UINT uCallbackMessage
Definition: shellapi.h:228
CHAR szTip[128]
Definition: shellapi.h:234
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW pnid)
Definition: systray.cpp:128
HICON TrayIcon_GetProcessorUsageIcon(void)
Definition: trayicon.c:26
BOOL TrayIcon_ShellRemoveTrayIcon(void)
Definition: trayicon.c:159
BOOL TrayIcon_ShellUpdateTrayIcon(void)
Definition: trayicon.c:177
BOOL TrayIcon_ShellAddTrayIcon(void)
Definition: trayicon.c:129
#define WM_ONTRAYICON
Definition: trayicon.h:25
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HICON WINAPI CreateIconIndirect(_In_ PICONINFO)
Definition: cursoricon.c:2550
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
HDC WINAPI GetDC(_In_opt_ HWND)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HBITMAP WINAPI LoadBitmapW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2132
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
__wchar_t WCHAR
Definition: xmlstorage.h:180