[TASKMGR] Refactor trayicon.c

This commit is contained in:
Katayama Hirofumi MZ 2023-06-15 13:26:20 +09:00
parent ad61c574f4
commit 99fb812be4

View file

@ -1,28 +1,16 @@
/*
* ReactOS Task Manager
*
* trayicon.c
*
* Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
* 2005 Klemens Friedl <frik85@reactos.at>
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* PROJECT: ReactOS Task Manager
* LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
* PURPOSE: Task Manager for ReactOS
* COPYRIGHT: Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
* Copyright (C) 2005 Klemens Friedl <frik85@reactos.at>
* Copyright (C) 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#include "precomp.h"
#include <strsafe.h>
HICON TrayIcon_GetProcessorUsageIcon(void)
{
HICON hTrayIcon = NULL;
@ -129,14 +117,11 @@ done:
BOOL TrayIcon_ShellAddTrayIcon(void)
{
NOTIFYICONDATAW nid;
HICON hIcon = NULL;
HICON hIcon = TrayIcon_GetProcessorUsageIcon();
BOOL bRetVal;
WCHAR szMsg[64];
memset(&nid, 0, sizeof(NOTIFYICONDATAW));
hIcon = TrayIcon_GetProcessorUsageIcon();
ZeroMemory(&nid, sizeof(nid));
nid.cbSize = sizeof(NOTIFYICONDATAW);
nid.hWnd = hMainWnd;
nid.uID = 0;
@ -144,9 +129,8 @@ BOOL TrayIcon_ShellAddTrayIcon(void)
nid.uCallbackMessage = WM_ONTRAYICON;
nid.hIcon = hIcon;
LoadStringW( GetModuleHandleW(NULL), IDS_MSG_TRAYICONCPUUSAGE, szMsg, sizeof(szMsg) / sizeof(szMsg[0]));
wsprintfW(nid.szTip, szMsg, PerfDataGetProcessorUsage());
LoadStringW(NULL, IDS_MSG_TRAYICONCPUUSAGE, szMsg, _countof(szMsg));
StringCchPrintfW(nid.szTip, _countof(nid.szTip), szMsg, PerfDataGetProcessorUsage());
bRetVal = Shell_NotifyIconW(NIM_ADD, &nid);
@ -159,40 +143,34 @@ BOOL TrayIcon_ShellAddTrayIcon(void)
BOOL TrayIcon_ShellRemoveTrayIcon(void)
{
NOTIFYICONDATAW nid;
BOOL bRetVal;
memset(&nid, 0, sizeof(NOTIFYICONDATAW));
ZeroMemory(&nid, sizeof(nid));
nid.cbSize = sizeof(NOTIFYICONDATAW);
nid.hWnd = hMainWnd;
nid.uID = 0;
nid.uFlags = 0;
nid.uCallbackMessage = WM_ONTRAYICON;
bRetVal = Shell_NotifyIconW(NIM_DELETE, &nid);
return bRetVal;
return Shell_NotifyIconW(NIM_DELETE, &nid);
}
BOOL TrayIcon_ShellUpdateTrayIcon(void)
{
NOTIFYICONDATAW nid;
HICON hIcon = NULL;
HICON hIcon = TrayIcon_GetProcessorUsageIcon();
BOOL bRetVal;
WCHAR szTemp[64];
memset(&nid, 0, sizeof(NOTIFYICONDATAW));
hIcon = TrayIcon_GetProcessorUsageIcon();
ZeroMemory(&nid, sizeof(nid));
nid.cbSize = sizeof(NOTIFYICONDATAW);
nid.hWnd = hMainWnd;
nid.uID = 0;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_ONTRAYICON;
nid.hIcon = hIcon;
LoadStringW(hInst, IDS_MSG_TRAYICONCPUUSAGE, szTemp, sizeof(szTemp)/sizeof(szTemp[0]));
wsprintfW(nid.szTip, szTemp, PerfDataGetProcessorUsage());
LoadStringW(NULL, IDS_MSG_TRAYICONCPUUSAGE, szTemp, _countof(szTemp));
StringCchPrintfW(nid.szTip, _countof(nid.szTip), szTemp, PerfDataGetProcessorUsage());
bRetVal = Shell_NotifyIconW(NIM_MODIFY, &nid);