ReactOS 0.4.15-dev-7953-g1f49173
trayicon.c File Reference
#include "precomp.h"
Include dependency graph for trayicon.c:

Go to the source code of this file.

Functions

static HICON TrayIcon_GetProcessorUsageIcon (_In_ ULONG CpuUsage)
 
static BOOL TrayIcon_Update (_In_ DWORD dwMessage)
 
BOOL TrayIcon_AddIcon (VOID)
 
BOOL TrayIcon_RemoveIcon (VOID)
 
BOOL TrayIcon_UpdateIcon (VOID)
 

Function Documentation

◆ TrayIcon_AddIcon()

BOOL TrayIcon_AddIcon ( VOID  )

Definition at line 138 of file trayicon.c.

139{
140 return TrayIcon_Update(NIM_ADD);
141}
#define NIM_ADD
Definition: shellapi.h:94
static BOOL TrayIcon_Update(_In_ DWORD dwMessage)
Definition: trayicon.c:103

Referenced by OnCreate().

◆ TrayIcon_GetProcessorUsageIcon()

static HICON TrayIcon_GetProcessorUsageIcon ( _In_ ULONG  CpuUsage)
static

Definition at line 12 of file trayicon.c.

14{
15 HICON hTrayIcon = NULL;
16 HDC hScreenDC = NULL;
17 HDC hDC = NULL;
19 HBITMAP hOldBitmap = NULL;
20 HBITMAP hBitmapMask = NULL;
21 ICONINFO iconInfo;
22 int nLinesToDraw;
23 HBRUSH hBitmapBrush = NULL;
24 RECT rc;
25
26 /* Get a handle to the screen DC */
27 hScreenDC = GetDC(NULL);
28 if (!hScreenDC)
29 goto done;
30
31 /* Create our own DC from it */
32 hDC = CreateCompatibleDC(hScreenDC);
33 if (!hDC)
34 goto done;
35
36 /*
37 * Load the bitmaps
38 */
41 if (!hBitmap || !hBitmapMask)
42 goto done;
43
44 hBitmapBrush = CreateSolidBrush(RGB(0, 255, 0));
45 if (!hBitmapBrush)
46 goto done;
47
48 /*
49 * Select the bitmap into our device context
50 * so we can draw on it.
51 */
52 hOldBitmap = SelectObject(hDC, hBitmap);
53
54 /*
55 * Calculate how many lines to draw
56 * since we have 11 rows of space
57 * to draw the cpu usage instead of
58 * just having 10.
59 */
60 nLinesToDraw = (CpuUsage + (CpuUsage / 10)) / 11;
61 rc.left = 3;
62 rc.top = 12 - nLinesToDraw;
63 rc.right = 13;
64 rc.bottom = 13;
65
66 /* Now draw the cpu usage */
67 if (nLinesToDraw)
68 FillRect(hDC, &rc, hBitmapBrush);
69
70 /*
71 * Now that we are done drawing put the
72 * old bitmap back.
73 */
74 hBitmap = SelectObject(hDC, hOldBitmap);
75 hOldBitmap = NULL;
76
77 iconInfo.fIcon = TRUE;
78 iconInfo.hbmMask = hBitmapMask;
79 iconInfo.hbmColor = hBitmap;
80
81 hTrayIcon = CreateIconIndirect(&iconInfo);
82
83done:
84 /*
85 * Cleanup
86 */
87 if (hScreenDC)
88 ReleaseDC(NULL, hScreenDC);
89 if (hDC)
91 if (hBitmapBrush)
92 DeleteObject(hBitmapBrush);
93 if (hBitmap)
95 if (hBitmapMask)
96 DeleteObject(hBitmapMask);
97
98 /* Return the newly created tray icon (if successful) */
99 return hTrayIcon;
100}
static HDC hDC
Definition: 3dtext.c:33
#define IDB_TRAYMASK
Definition: resource.h:33
#define IDB_TRAYICON
Definition: resource.h:34
#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:71
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
BOOL fIcon
Definition: winuser.h:3123
HBITMAP hbmColor
Definition: winuser.h:3127
HBITMAP hbmMask
Definition: winuser.h:3126
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
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:2581
HDC WINAPI GetDC(_In_opt_ HWND)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HBITMAP WINAPI LoadBitmapW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2163

Referenced by TrayIcon_Update().

◆ TrayIcon_RemoveIcon()

BOOL TrayIcon_RemoveIcon ( VOID  )

Definition at line 143 of file trayicon.c.

144{
146
147 ZeroMemory(&nid, sizeof(nid));
148
149 nid.cbSize = sizeof(nid);
150 nid.hWnd = hMainWnd;
151 nid.uID = 0;
152 nid.uFlags = 0;
154
156}
HWND hMainWnd
Definition: magnifier.c:32
NOTIFYICONDATA nid
Definition: magnifier.c:44
#define NIM_DELETE
Definition: shellapi.h:96
UINT uCallbackMessage
Definition: shellapi.h:231
BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW pnid)
Definition: systray.cpp:128
#define WM_ONTRAYICON
Definition: trayicon.h:11
#define ZeroMemory
Definition: winbase.h:1712

Referenced by TaskManagerWndProc().

◆ TrayIcon_Update()

static BOOL TrayIcon_Update ( _In_ DWORD  dwMessage)
static

Definition at line 103 of file trayicon.c.

105{
106 static WCHAR szMsg[64] = L"";
107
109 ULONG CpuUsage;
110 HICON hIcon = NULL;
111 BOOL bRetVal;
112
113 if (!*szMsg)
115
116 ZeroMemory(&nid, sizeof(nid));
117
118 CpuUsage = PerfDataGetProcessorUsage();
120
121 nid.cbSize = sizeof(nid);
122 nid.hWnd = hMainWnd;
123 nid.uID = 0;
126 nid.hIcon = hIcon;
127
128 StringCchPrintfW(nid.szTip, _countof(nid.szTip), szMsg, CpuUsage);
129
130 bRetVal = Shell_NotifyIconW(dwMessage, &nid);
131
132 if (hIcon)
134
135 return bRetVal;
136}
#define IDS_MSG_TRAYICONCPUUSAGE
Definition: resource.h:257
unsigned int BOOL
Definition: ntddk_ex.h:94
HICON hIcon
Definition: msconfig.c:44
#define L(x)
Definition: ntvdm.h:50
ULONG PerfDataGetProcessorUsage(void)
Definition: perfdata.c:455
#define NIF_ICON
Definition: shellapi.h:106
#define NIF_MESSAGE
Definition: shellapi.h:105
#define NIF_TIP
Definition: shellapi.h:107
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
CHAR szTip[128]
Definition: shellapi.h:237
static HICON TrayIcon_GetProcessorUsageIcon(_In_ ULONG CpuUsage)
Definition: trayicon.c:12
uint32_t ULONG
Definition: typedefs.h:59
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2053
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by TrayIcon_AddIcon(), and TrayIcon_UpdateIcon().

◆ TrayIcon_UpdateIcon()

BOOL TrayIcon_UpdateIcon ( VOID  )

Definition at line 158 of file trayicon.c.

159{
161}
#define NIM_MODIFY
Definition: shellapi.h:95

Referenced by TaskManagerWndProc().