ReactOS  0.4.12-dev-102-g4b7f1e0
trayicon.c File Reference
#include "precomp.h"
Include dependency graph for trayicon.c:

Go to the source code of this file.

Functions

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

Function Documentation

◆ TrayIcon_GetProcessorUsageIcon()

HICON TrayIcon_GetProcessorUsageIcon ( void  )

Definition at line 26 of file trayicon.c.

Referenced by TrayIcon_ShellAddTrayIcon(), and TrayIcon_ShellUpdateTrayIcon().

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 
108 done:
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)
119  DeleteObject(hBitmap);
120  if (hBitmapMask)
121  DeleteObject(hBitmapMask);
122 
123  /*
124  * Return the newly created tray icon (if successful)
125  */
126  return hTrayIcon;
127 }
#define HDC
Definition: msvc.h:22
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
#define HBITMAP
Definition: msvc.h:28
HDC WINAPI GetDC(_In_opt_ HWND)
LONG top
Definition: windef.h:297
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define IDB_TRAYICON
Definition: resource.h:27
LONG left
Definition: windef.h:296
LONG right
Definition: windef.h:298
HBITMAP hbmMask
Definition: winuser.h:3079
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define IDB_TRAYMASK
Definition: resource.h:26
smooth NULL
Definition: ftsmooth.c:416
HBITMAP hbmColor
Definition: winuser.h:3080
BOOL fIcon
Definition: winuser.h:3076
HICON WINAPI CreateIconIndirect(_In_ PICONINFO)
Definition: cursoricon.c:2546
#define RGB(r, g, b)
Definition: wingdi.h:2917
static HDC hDC
Definition: 3dtext.c:33
HINSTANCE hInst
Definition: dxdiag.c:13
BOOL WINAPI DeleteDC(_In_ HDC)
HBITMAP WINAPI LoadBitmapW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2132
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
unsigned int ULONG
Definition: retypes.h:1
LONG bottom
Definition: windef.h:299
ULONG PerfDataGetProcessorUsage(void)
Definition: perfdata.c:481
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
static HBITMAP hBitmap
Definition: timezone.c:34

◆ TrayIcon_ShellAddTrayIcon()

BOOL TrayIcon_ShellAddTrayIcon ( void  )

Definition at line 129 of file trayicon.c.

Referenced by OnCreate().

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)
154  DestroyIcon(hIcon);
155 
156  return bRetVal;
157 }
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
#define NIF_MESSAGE
Definition: shellapi.h:102
static HICON
Definition: imagelist.c:84
NOTIFYICONDATA nid
Definition: magnifier.c:45
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
__wchar_t WCHAR
Definition: xmlstorage.h:180
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
UINT uCallbackMessage
Definition: shellapi.h:257
#define NIF_TIP
Definition: shellapi.h:104
smooth NULL
Definition: ftsmooth.c:416
#define NIF_ICON
Definition: shellapi.h:103
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDS_MSG_TRAYICONCPUUSAGE
Definition: resource.h:251
#define WM_ONTRAYICON
Definition: trayicon.h:25
HWND hMainWnd
Definition: magnifier.c:33
struct _NOTIFYICONDATAW NOTIFYICONDATAW
HICON hIcon
Definition: msconfig.c:44
#define NIM_ADD
Definition: shellapi.h:91
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
ULONG PerfDataGetProcessorUsage(void)
Definition: perfdata.c:481
WCHAR szTip[128]
Definition: shellapi.h:263
#define memset(x, y, z)
Definition: compat.h:39
BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW pnid)
Definition: systray.cpp:128
HICON TrayIcon_GetProcessorUsageIcon(void)
Definition: trayicon.c:26

◆ TrayIcon_ShellRemoveTrayIcon()

BOOL TrayIcon_ShellRemoveTrayIcon ( void  )

Definition at line 159 of file trayicon.c.

Referenced by TaskManagerWndProc().

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 }
NOTIFYICONDATA nid
Definition: magnifier.c:45
UINT uCallbackMessage
Definition: shellapi.h:257
unsigned int BOOL
Definition: ntddk_ex.h:94
#define NIM_DELETE
Definition: shellapi.h:93
#define WM_ONTRAYICON
Definition: trayicon.h:25
HWND hMainWnd
Definition: magnifier.c:33
struct _NOTIFYICONDATAW NOTIFYICONDATAW
#define memset(x, y, z)
Definition: compat.h:39
BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW pnid)
Definition: systray.cpp:128

◆ TrayIcon_ShellUpdateTrayIcon()

BOOL TrayIcon_ShellUpdateTrayIcon ( void  )

Definition at line 177 of file trayicon.c.

Referenced by TaskManagerWndProc().

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]));
195  wsprintfW(nid.szTip, szTemp, PerfDataGetProcessorUsage());
196 
197  bRetVal = Shell_NotifyIconW(NIM_MODIFY, &nid);
198 
199  if (hIcon)
200  DestroyIcon(hIcon);
201 
202  return bRetVal;
203 }
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
#define NIF_MESSAGE
Definition: shellapi.h:102
static HICON
Definition: imagelist.c:84
NOTIFYICONDATA nid
Definition: magnifier.c:45
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
__wchar_t WCHAR
Definition: xmlstorage.h:180
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
UINT uCallbackMessage
Definition: shellapi.h:257
#define NIF_TIP
Definition: shellapi.h:104
smooth NULL
Definition: ftsmooth.c:416
#define NIF_ICON
Definition: shellapi.h:103
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDS_MSG_TRAYICONCPUUSAGE
Definition: resource.h:251
#define WM_ONTRAYICON
Definition: trayicon.h:25
HWND hMainWnd
Definition: magnifier.c:33
struct _NOTIFYICONDATAW NOTIFYICONDATAW
HINSTANCE hInst
Definition: dxdiag.c:13
HICON hIcon
Definition: msconfig.c:44
ULONG PerfDataGetProcessorUsage(void)
Definition: perfdata.c:481
WCHAR szTip[128]
Definition: shellapi.h:263
#define memset(x, y, z)
Definition: compat.h:39
BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW pnid)
Definition: systray.cpp:128
#define NIM_MODIFY
Definition: shellapi.h:92
HICON TrayIcon_GetProcessorUsageIcon(void)
Definition: trayicon.c:26