ReactOS 0.4.15-dev-5669-g09dde2c
trayicon.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WM_ONTRAYICON   WM_USER + 5
 

Functions

HICON TrayIcon_GetProcessorUsageIcon (void)
 
BOOL TrayIcon_ShellAddTrayIcon (void)
 
BOOL TrayIcon_ShellRemoveTrayIcon (void)
 
BOOL TrayIcon_ShellUpdateTrayIcon (void)
 

Macro Definition Documentation

◆ WM_ONTRAYICON

#define WM_ONTRAYICON   WM_USER + 5

Definition at line 25 of file trayicon.h.

Function Documentation

◆ TrayIcon_GetProcessorUsageIcon()

HICON TrayIcon_GetProcessorUsageIcon ( void  )

Definition at line 26 of file trayicon.c.

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}
static HDC hDC
Definition: 3dtext.c:33
#define IDB_TRAYMASK
Definition: resource.h:26
#define IDB_TRAYICON
Definition: resource.h:27
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
static HBITMAP hBitmap
Definition: timezone.c:26
#define RGB(r, g, b)
Definition: precomp.h:62
HINSTANCE hInst
Definition: dxdiag.c:13
pKey DeleteObject()
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
static HICON
Definition: imagelist.c:84
ULONG PerfDataGetProcessorUsage(void)
Definition: perfdata.c:472
BOOL fIcon
Definition: winuser.h:3113
HBITMAP hbmColor
Definition: winuser.h:3117
HBITMAP hbmMask
Definition: winuser.h:3116
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
uint32_t ULONG
Definition: typedefs.h:59
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
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

Referenced by TrayIcon_ShellAddTrayIcon(), and TrayIcon_ShellUpdateTrayIcon().

◆ TrayIcon_ShellAddTrayIcon()

BOOL TrayIcon_ShellAddTrayIcon ( void  )

Definition at line 129 of file trayicon.c.

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}
#define IDS_MSG_TRAYICONCPUUSAGE
Definition: resource.h:252
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
unsigned int BOOL
Definition: ntddk_ex.h:94
HWND hMainWnd
Definition: magnifier.c:32
NOTIFYICONDATA nid
Definition: magnifier.c:44
HICON hIcon
Definition: msconfig.c:44
#define memset(x, y, z)
Definition: compat.h:39
struct _NOTIFYICONDATAW NOTIFYICONDATAW
#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
UINT uCallbackMessage
Definition: shellapi.h:228
CHAR szTip[128]
Definition: shellapi.h:234
BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW pnid)
Definition: systray.cpp:128
HICON TrayIcon_GetProcessorUsageIcon(void)
Definition: trayicon.c:26
#define WM_ONTRAYICON
Definition: trayicon.h:25
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,...)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by OnCreate().

◆ TrayIcon_ShellRemoveTrayIcon()

BOOL TrayIcon_ShellRemoveTrayIcon ( void  )

Definition at line 159 of file trayicon.c.

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}
#define NIM_DELETE
Definition: shellapi.h:93

Referenced by TaskManagerWndProc().

◆ TrayIcon_ShellUpdateTrayIcon()

BOOL TrayIcon_ShellUpdateTrayIcon ( void  )

Definition at line 177 of file trayicon.c.

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}
#define NIM_MODIFY
Definition: shellapi.h:92

Referenced by TaskManagerWndProc().