2004-03-23 02:19:54 +01:00
|
|
|
/*
|
|
|
|
* ReactOS Task Manager
|
|
|
|
*
|
|
|
|
* trayicon.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-03-23 02:19:54 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <winnt.h>
|
2008-08-01 09:18:25 +02:00
|
|
|
#include <shellapi.h>
|
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
2004-03-23 02:19:54 +01:00
|
|
|
#include "taskmgr.h"
|
|
|
|
#include "perfdata.h"
|
|
|
|
|
2009-02-05 00:19:35 +01:00
|
|
|
static HICON TrayIcon_GetProcessorUsageIcon(void)
|
2004-03-23 02:19:54 +01:00
|
|
|
{
|
|
|
|
HICON hTrayIcon = NULL;
|
|
|
|
HDC hScreenDC = NULL;
|
|
|
|
HDC hDC = NULL;
|
|
|
|
HBITMAP hBitmap = NULL;
|
2006-09-10 21:15:11 +02:00
|
|
|
HBITMAP hOldBitmap;
|
2004-03-23 02:19:54 +01:00
|
|
|
HBITMAP hBitmapMask = NULL;
|
|
|
|
ICONINFO iconInfo;
|
|
|
|
ULONG ProcessorUsage;
|
|
|
|
int nLinesToDraw;
|
|
|
|
HBRUSH hBitmapBrush = NULL;
|
|
|
|
RECT rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a handle to the screen DC
|
|
|
|
*/
|
|
|
|
hScreenDC = GetDC(NULL);
|
|
|
|
if (!hScreenDC)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create our own DC from it
|
|
|
|
*/
|
|
|
|
hDC = CreateCompatibleDC(hScreenDC);
|
|
|
|
if (!hDC)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the bitmaps
|
|
|
|
*/
|
2011-05-17 12:15:28 +02:00
|
|
|
hBitmap = LoadBitmapW(hInst, MAKEINTRESOURCEW(IDB_TRAYICON));
|
|
|
|
hBitmapMask = LoadBitmapW(hInst, MAKEINTRESOURCEW(IDB_TRAYMASK));
|
2004-03-23 02:19:54 +01:00
|
|
|
if (!hBitmap || !hBitmapMask)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hBitmapBrush = CreateSolidBrush(RGB(0, 255, 0));
|
|
|
|
if (!hBitmapBrush)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Select the bitmap into our device context
|
|
|
|
* so we can draw on it.
|
|
|
|
*/
|
2008-10-25 23:39:55 +02:00
|
|
|
hOldBitmap = SelectObject(hDC, hBitmap);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the cpu usage
|
|
|
|
*/
|
|
|
|
ProcessorUsage = PerfDataGetProcessorUsage();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate how many lines to draw
|
|
|
|
* since we have 11 rows of space
|
|
|
|
* to draw the cpu usage instead of
|
|
|
|
* just having 10.
|
|
|
|
*/
|
|
|
|
nLinesToDraw = (ProcessorUsage + (ProcessorUsage / 10)) / 11;
|
|
|
|
rc.left = 3;
|
|
|
|
rc.top = 12 - nLinesToDraw;
|
|
|
|
rc.right = 13;
|
|
|
|
rc.bottom = 13;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now draw the cpu usage
|
|
|
|
*/
|
|
|
|
if (nLinesToDraw)
|
|
|
|
FillRect(hDC, &rc, hBitmapBrush);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we are done drawing put the
|
|
|
|
* old bitmap back.
|
|
|
|
*/
|
|
|
|
SelectObject(hDC, hOldBitmap);
|
2006-09-10 21:15:11 +02:00
|
|
|
|
2004-03-23 02:19:54 +01:00
|
|
|
iconInfo.fIcon = TRUE;
|
|
|
|
iconInfo.xHotspot = 0;
|
|
|
|
iconInfo.yHotspot = 0;
|
|
|
|
iconInfo.hbmMask = hBitmapMask;
|
|
|
|
iconInfo.hbmColor = hBitmap;
|
|
|
|
|
|
|
|
hTrayIcon = CreateIconIndirect(&iconInfo);
|
|
|
|
|
|
|
|
done:
|
|
|
|
/*
|
|
|
|
* Cleanup
|
|
|
|
*/
|
|
|
|
if (hScreenDC)
|
|
|
|
ReleaseDC(NULL, hScreenDC);
|
|
|
|
if (hDC)
|
|
|
|
DeleteDC(hDC);
|
|
|
|
if (hBitmapBrush)
|
|
|
|
DeleteObject(hBitmapBrush);
|
|
|
|
if (hBitmap)
|
|
|
|
DeleteObject(hBitmap);
|
|
|
|
if (hBitmapMask)
|
|
|
|
DeleteObject(hBitmapMask);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the newly created tray icon (if successful)
|
|
|
|
*/
|
|
|
|
return hTrayIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL TrayIcon_ShellAddTrayIcon(void)
|
|
|
|
{
|
2008-08-01 09:18:25 +02:00
|
|
|
NOTIFYICONDATAW nid;
|
2004-03-23 02:19:54 +01:00
|
|
|
HICON hIcon = NULL;
|
|
|
|
BOOL bRetVal;
|
2009-06-25 21:43:11 +02:00
|
|
|
WCHAR wszCPU_Usage[255];
|
|
|
|
|
|
|
|
LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR));
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2008-08-01 09:18:25 +02:00
|
|
|
memset(&nid, 0, sizeof(NOTIFYICONDATAW));
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
hIcon = TrayIcon_GetProcessorUsageIcon();
|
|
|
|
|
2008-08-01 09:18:25 +02:00
|
|
|
nid.cbSize = sizeof(NOTIFYICONDATAW);
|
2004-03-23 02:19:54 +01:00
|
|
|
nid.hWnd = hMainWnd;
|
|
|
|
nid.uID = 0;
|
|
|
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
2005-09-14 21:17:12 +02:00
|
|
|
nid.uCallbackMessage = WM_ONTRAYICON;
|
2004-03-23 02:19:54 +01:00
|
|
|
nid.hIcon = hIcon;
|
2008-08-01 09:18:25 +02:00
|
|
|
wsprintfW(nid.szTip, wszCPU_Usage, PerfDataGetProcessorUsage());
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2008-08-01 09:18:25 +02:00
|
|
|
bRetVal = Shell_NotifyIconW(NIM_ADD, &nid);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
if (hIcon)
|
|
|
|
DestroyIcon(hIcon);
|
|
|
|
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL TrayIcon_ShellRemoveTrayIcon(void)
|
|
|
|
{
|
2008-08-01 09:18:25 +02:00
|
|
|
NOTIFYICONDATAW nid;
|
2004-03-23 02:19:54 +01:00
|
|
|
BOOL bRetVal;
|
|
|
|
|
2008-08-01 09:18:25 +02:00
|
|
|
memset(&nid, 0, sizeof(NOTIFYICONDATAW));
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2008-08-01 09:18:25 +02:00
|
|
|
nid.cbSize = sizeof(NOTIFYICONDATAW);
|
2004-03-23 02:19:54 +01:00
|
|
|
nid.hWnd = hMainWnd;
|
|
|
|
nid.uID = 0;
|
|
|
|
nid.uFlags = 0;
|
2005-09-14 21:17:12 +02:00
|
|
|
nid.uCallbackMessage = WM_ONTRAYICON;
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2008-08-01 09:18:25 +02:00
|
|
|
bRetVal = Shell_NotifyIconW(NIM_DELETE, &nid);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL TrayIcon_ShellUpdateTrayIcon(void)
|
|
|
|
{
|
2008-08-01 09:18:25 +02:00
|
|
|
NOTIFYICONDATAW nid;
|
2004-03-23 02:19:54 +01:00
|
|
|
HICON hIcon = NULL;
|
|
|
|
BOOL bRetVal;
|
2009-06-25 21:43:11 +02:00
|
|
|
WCHAR wszCPU_Usage[255];
|
|
|
|
|
|
|
|
LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR));
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2008-08-01 09:18:25 +02:00
|
|
|
memset(&nid, 0, sizeof(NOTIFYICONDATAW));
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
hIcon = TrayIcon_GetProcessorUsageIcon();
|
|
|
|
|
2008-08-01 09:18:25 +02:00
|
|
|
nid.cbSize = sizeof(NOTIFYICONDATAW);
|
2004-03-23 02:19:54 +01:00
|
|
|
nid.hWnd = hMainWnd;
|
|
|
|
nid.uID = 0;
|
|
|
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
2005-09-14 21:17:12 +02:00
|
|
|
nid.uCallbackMessage = WM_ONTRAYICON;
|
2004-03-23 02:19:54 +01:00
|
|
|
nid.hIcon = hIcon;
|
2008-08-01 09:18:25 +02:00
|
|
|
wsprintfW(nid.szTip, wszCPU_Usage, PerfDataGetProcessorUsage());
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2008-08-01 09:18:25 +02:00
|
|
|
bRetVal = Shell_NotifyIconW(NIM_MODIFY, &nid);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
if (hIcon)
|
|
|
|
DestroyIcon(hIcon);
|
|
|
|
|
|
|
|
return bRetVal;
|
|
|
|
}
|