mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 07:53:07 +00:00
[STOBJECT] Store the "Show x icon in the taskbar" setting for the hotplug, power and volume icons.
CORE-12365 CORE-12972 CORE-15234
This commit is contained in:
parent
22411ef223
commit
8c30fdab1c
6 changed files with 128 additions and 36 deletions
|
@ -13,15 +13,80 @@
|
||||||
#include <shellutils.h>
|
#include <shellutils.h>
|
||||||
|
|
||||||
SysTrayIconHandlers_t g_IconHandlers [] = {
|
SysTrayIconHandlers_t g_IconHandlers [] = {
|
||||||
{ Volume_Init, Volume_Shutdown, Volume_Update, Volume_Message },
|
{ VOLUME_SERVICE_FLAG, Volume_Init, Volume_Shutdown, Volume_Update, Volume_Message },
|
||||||
{ Hotplug_Init, Hotplug_Shutdown, Hotplug_Update, Hotplug_Message },
|
{ HOTPLUG_SERVICE_FLAG, Hotplug_Init, Hotplug_Shutdown, Hotplug_Update, Hotplug_Message },
|
||||||
{ Power_Init, Power_Shutdown, Power_Update, Power_Message }
|
{ POWER_SERVICE_FLAG, Power_Init, Power_Shutdown, Power_Update, Power_Message }
|
||||||
};
|
};
|
||||||
const int g_NumIcons = _countof(g_IconHandlers);
|
const int g_NumIcons = _countof(g_IconHandlers);
|
||||||
|
|
||||||
CSysTray::CSysTray() {}
|
CSysTray::CSysTray() {}
|
||||||
CSysTray::~CSysTray() {}
|
CSysTray::~CSysTray() {}
|
||||||
|
|
||||||
|
VOID CSysTray::GetServicesEnabled()
|
||||||
|
{
|
||||||
|
HKEY hKey;
|
||||||
|
DWORD dwSize;
|
||||||
|
|
||||||
|
/* Enable power and volume by default */
|
||||||
|
this->dwServicesEnabled = POWER_SERVICE_FLAG | VOLUME_SERVICE_FLAG;
|
||||||
|
|
||||||
|
if (RegCreateKeyExW(HKEY_CURRENT_USER,
|
||||||
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\SysTray",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
REG_OPTION_NON_VOLATILE,
|
||||||
|
KEY_READ,
|
||||||
|
NULL,
|
||||||
|
&hKey,
|
||||||
|
NULL) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
dwSize = sizeof(DWORD);
|
||||||
|
RegQueryValueExW(hKey,
|
||||||
|
L"Services",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
(LPBYTE)&this->dwServicesEnabled,
|
||||||
|
&dwSize);
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID CSysTray::EnableService(DWORD dwServiceFlag, BOOL bEnable)
|
||||||
|
{
|
||||||
|
HKEY hKey;
|
||||||
|
|
||||||
|
if (bEnable)
|
||||||
|
this->dwServicesEnabled |= dwServiceFlag;
|
||||||
|
else
|
||||||
|
this->dwServicesEnabled &= ~dwServiceFlag;
|
||||||
|
|
||||||
|
if (RegCreateKeyExW(HKEY_CURRENT_USER,
|
||||||
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\SysTray",
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
REG_OPTION_NON_VOLATILE,
|
||||||
|
KEY_WRITE,
|
||||||
|
NULL,
|
||||||
|
&hKey,
|
||||||
|
NULL) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
RegSetValueExW(hKey,
|
||||||
|
L"Services",
|
||||||
|
0,
|
||||||
|
REG_DWORD,
|
||||||
|
(LPBYTE)&this->dwServicesEnabled,
|
||||||
|
sizeof(DWORD));
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CSysTray::IsServiceEnabled(DWORD dwServiceFlag)
|
||||||
|
{
|
||||||
|
return (this->dwServicesEnabled & dwServiceFlag);
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT CSysTray::InitNetShell()
|
HRESULT CSysTray::InitNetShell()
|
||||||
{
|
{
|
||||||
HRESULT hr = CoCreateInstance(CLSID_ConnectionTray, 0, 1u, IID_PPV_ARG(IOleCommandTarget, &pctNetShell));
|
HRESULT hr = CoCreateInstance(CLSID_ConnectionTray, 0, 1u, IID_PPV_ARG(IOleCommandTarget, &pctNetShell));
|
||||||
|
@ -49,9 +114,12 @@ HRESULT CSysTray::InitIcons()
|
||||||
TRACE("Initializing Notification icons...\n");
|
TRACE("Initializing Notification icons...\n");
|
||||||
for (int i = 0; i < g_NumIcons; i++)
|
for (int i = 0; i < g_NumIcons; i++)
|
||||||
{
|
{
|
||||||
HRESULT hr = g_IconHandlers[i].pfnInit(this);
|
if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
|
||||||
if (FAILED(hr))
|
{
|
||||||
return hr;
|
HRESULT hr = g_IconHandlers[i].pfnInit(this);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return InitNetShell();
|
return InitNetShell();
|
||||||
|
@ -62,9 +130,12 @@ HRESULT CSysTray::ShutdownIcons()
|
||||||
TRACE("Shutting down Notification icons...\n");
|
TRACE("Shutting down Notification icons...\n");
|
||||||
for (int i = 0; i < g_NumIcons; i++)
|
for (int i = 0; i < g_NumIcons; i++)
|
||||||
{
|
{
|
||||||
HRESULT hr = g_IconHandlers[i].pfnShutdown(this);
|
if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
|
||||||
if (FAILED(hr))
|
{
|
||||||
return hr;
|
HRESULT hr = g_IconHandlers[i].pfnShutdown(this);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ShutdownNetShell();
|
return ShutdownNetShell();
|
||||||
|
@ -75,9 +146,12 @@ HRESULT CSysTray::UpdateIcons()
|
||||||
TRACE("Updating Notification icons...\n");
|
TRACE("Updating Notification icons...\n");
|
||||||
for (int i = 0; i < g_NumIcons; i++)
|
for (int i = 0; i < g_NumIcons; i++)
|
||||||
{
|
{
|
||||||
HRESULT hr = g_IconHandlers[i].pfnUpdate(this);
|
if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
|
||||||
if (FAILED(hr))
|
{
|
||||||
return hr;
|
HRESULT hr = g_IconHandlers[i].pfnUpdate(this);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
@ -236,6 +310,7 @@ BOOL CSysTray::ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
|
GetServicesEnabled();
|
||||||
InitIcons();
|
InitIcons();
|
||||||
SetTimer(1, 2000, NULL);
|
SetTimer(1, 2000, NULL);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -28,6 +28,7 @@ class CSysTray :
|
||||||
|
|
||||||
// TODO: keep icon handlers here
|
// TODO: keep icon handlers here
|
||||||
|
|
||||||
|
DWORD dwServicesEnabled;
|
||||||
HWND hwndSysTray;
|
HWND hwndSysTray;
|
||||||
|
|
||||||
static DWORD WINAPI s_SysTrayThreadProc(PVOID param);
|
static DWORD WINAPI s_SysTrayThreadProc(PVOID param);
|
||||||
|
@ -44,11 +45,16 @@ class CSysTray :
|
||||||
HRESULT InitNetShell();
|
HRESULT InitNetShell();
|
||||||
HRESULT ShutdownNetShell();
|
HRESULT ShutdownNetShell();
|
||||||
|
|
||||||
|
VOID GetServicesEnabled();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HRESULT NotifyIcon(INT code, UINT uId, HICON hIcon, LPCWSTR szTip, DWORD dwstate = 0);
|
HRESULT NotifyIcon(INT code, UINT uId, HICON hIcon, LPCWSTR szTip, DWORD dwstate = 0);
|
||||||
|
|
||||||
HWND GetHWnd() { return m_hWnd; }
|
HWND GetHWnd() { return m_hWnd; }
|
||||||
|
|
||||||
|
VOID EnableService(DWORD dwServiceFlag, BOOL bEnable);
|
||||||
|
BOOL IsServiceEnabled(DWORD dwServiceFlag);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult, DWORD dwMsgMapID = 0);
|
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult, DWORD dwMsgMapID = 0);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ CSimpleArray<DEVINST> g_devList;
|
||||||
static HICON g_hIconHotplug = NULL;
|
static HICON g_hIconHotplug = NULL;
|
||||||
static LPCWSTR g_strTooltip = L"Safely Remove Hardware and Eject Media";
|
static LPCWSTR g_strTooltip = L"Safely Remove Hardware and Eject Media";
|
||||||
static WCHAR g_strMenuSel[DISPLAY_NAME_LEN];
|
static WCHAR g_strMenuSel[DISPLAY_NAME_LEN];
|
||||||
static BOOL g_IsRunning = FALSE;
|
|
||||||
static BOOL g_IsRemoving = FALSE;
|
static BOOL g_IsRemoving = FALSE;
|
||||||
|
|
||||||
/*++
|
/*++
|
||||||
|
@ -132,7 +131,6 @@ HRESULT STDMETHODCALLTYPE Hotplug_Init(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
TRACE("Hotplug_Init\n");
|
TRACE("Hotplug_Init\n");
|
||||||
g_hIconHotplug = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_HOTPLUG_OK));
|
g_hIconHotplug = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_HOTPLUG_OK));
|
||||||
g_IsRunning = TRUE;
|
|
||||||
EnumHotpluggedDevices(g_devList);
|
EnumHotpluggedDevices(g_devList);
|
||||||
|
|
||||||
return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip, NIS_HIDDEN);
|
return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip, NIS_HIDDEN);
|
||||||
|
@ -152,8 +150,6 @@ HRESULT STDMETHODCALLTYPE Hotplug_Shutdown(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
TRACE("Hotplug_Shutdown\n");
|
TRACE("Hotplug_Shutdown\n");
|
||||||
|
|
||||||
g_IsRunning = FALSE;
|
|
||||||
|
|
||||||
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_HOTPLUG, NULL, NULL);
|
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_HOTPLUG, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,20 +259,26 @@ HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray, UINT uMsg, W
|
||||||
|
|
||||||
case WM_USER + 220:
|
case WM_USER + 220:
|
||||||
TRACE("Hotplug_Message: WM_USER+220\n");
|
TRACE("Hotplug_Message: WM_USER+220\n");
|
||||||
if (wParam == 1)
|
if (wParam == HOTPLUG_SERVICE_FLAG)
|
||||||
{
|
{
|
||||||
if (lParam == FALSE)
|
if (lParam)
|
||||||
|
{
|
||||||
|
pSysTray->EnableService(HOTPLUG_SERVICE_FLAG, TRUE);
|
||||||
return Hotplug_Init(pSysTray);
|
return Hotplug_Init(pSysTray);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
pSysTray->EnableService(HOTPLUG_SERVICE_FLAG, FALSE);
|
||||||
return Hotplug_Shutdown(pSysTray);
|
return Hotplug_Shutdown(pSysTray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
case WM_USER + 221:
|
case WM_USER + 221:
|
||||||
TRACE("Hotplug_Message: WM_USER+221\n");
|
TRACE("Hotplug_Message: WM_USER+221\n");
|
||||||
if (wParam == 1)
|
if (wParam == HOTPLUG_SERVICE_FLAG)
|
||||||
{
|
{
|
||||||
lResult = (LRESULT)g_IsRunning;
|
lResult = (LRESULT)pSysTray->IsServiceEnabled(HOTPLUG_SERVICE_FLAG);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
|
@ -28,7 +28,6 @@ typedef struct _PWRSCHEMECONTEXT
|
||||||
|
|
||||||
CString g_strTooltip;
|
CString g_strTooltip;
|
||||||
static HICON g_hIconBattery = NULL;
|
static HICON g_hIconBattery = NULL;
|
||||||
static BOOL g_IsRunning = FALSE;
|
|
||||||
|
|
||||||
|
|
||||||
/*++
|
/*++
|
||||||
|
@ -117,7 +116,6 @@ HRESULT STDMETHODCALLTYPE Power_Init(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
TRACE("Power_Init\n");
|
TRACE("Power_Init\n");
|
||||||
g_hIconBattery = DynamicLoadIcon(g_hInstance);
|
g_hIconBattery = DynamicLoadIcon(g_hInstance);
|
||||||
g_IsRunning = TRUE;
|
|
||||||
|
|
||||||
return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_POWER, g_hIconBattery, g_strTooltip);
|
return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_POWER, g_hIconBattery, g_strTooltip);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +131,6 @@ HRESULT STDMETHODCALLTYPE Power_Update(_In_ CSysTray * pSysTray)
|
||||||
HRESULT STDMETHODCALLTYPE Power_Shutdown(_In_ CSysTray * pSysTray)
|
HRESULT STDMETHODCALLTYPE Power_Shutdown(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
TRACE("Power_Shutdown\n");
|
TRACE("Power_Shutdown\n");
|
||||||
g_IsRunning = FALSE;
|
|
||||||
|
|
||||||
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_POWER, NULL, NULL);
|
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_POWER, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
@ -238,20 +235,26 @@ HRESULT STDMETHODCALLTYPE Power_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPA
|
||||||
{
|
{
|
||||||
case WM_USER + 220:
|
case WM_USER + 220:
|
||||||
TRACE("Power_Message: WM_USER+220\n");
|
TRACE("Power_Message: WM_USER+220\n");
|
||||||
if (wParam == 1)
|
if (wParam == POWER_SERVICE_FLAG)
|
||||||
{
|
{
|
||||||
if (lParam == FALSE)
|
if (lParam)
|
||||||
|
{
|
||||||
|
pSysTray->EnableService(POWER_SERVICE_FLAG, TRUE);
|
||||||
return Power_Init(pSysTray);
|
return Power_Init(pSysTray);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
pSysTray->EnableService(POWER_SERVICE_FLAG, FALSE);
|
||||||
return Power_Shutdown(pSysTray);
|
return Power_Shutdown(pSysTray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
case WM_USER + 221:
|
case WM_USER + 221:
|
||||||
TRACE("Power_Message: WM_USER+221\n");
|
TRACE("Power_Message: WM_USER+221\n");
|
||||||
if (wParam == 1)
|
if (wParam == POWER_SERVICE_FLAG)
|
||||||
{
|
{
|
||||||
lResult = (LRESULT)g_IsRunning;
|
lResult = (LRESULT)pSysTray->IsServiceEnabled(POWER_SERVICE_FLAG);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
|
@ -34,6 +34,10 @@ extern HINSTANCE g_hInstance;
|
||||||
#define ID_ICON_HOTPLUG (WM_APP + 0x4CC)
|
#define ID_ICON_HOTPLUG (WM_APP + 0x4CC)
|
||||||
#define ID_ICON_POWER (WM_APP + 0x4CD)
|
#define ID_ICON_POWER (WM_APP + 0x4CD)
|
||||||
|
|
||||||
|
#define POWER_SERVICE_FLAG 0x00000001
|
||||||
|
#define HOTPLUG_SERVICE_FLAG 0x00000002
|
||||||
|
#define VOLUME_SERVICE_FLAG 0x00000004
|
||||||
|
|
||||||
#include "csystray.h"
|
#include "csystray.h"
|
||||||
|
|
||||||
typedef HRESULT(STDMETHODCALLTYPE * PFNSTINIT) (_In_ CSysTray * pSysTray);
|
typedef HRESULT(STDMETHODCALLTYPE * PFNSTINIT) (_In_ CSysTray * pSysTray);
|
||||||
|
@ -43,6 +47,7 @@ typedef HRESULT(STDMETHODCALLTYPE * PFNSTMESSAGE) (_In_ CSysTray * pSysTray, UI
|
||||||
|
|
||||||
struct SysTrayIconHandlers_t
|
struct SysTrayIconHandlers_t
|
||||||
{
|
{
|
||||||
|
DWORD dwServiceFlag;
|
||||||
PFNSTINIT pfnInit;
|
PFNSTINIT pfnInit;
|
||||||
PFNSTSHUTDOWN pfnShutdown;
|
PFNSTSHUTDOWN pfnShutdown;
|
||||||
PFNSTUPDATE pfnUpdate;
|
PFNSTUPDATE pfnUpdate;
|
||||||
|
|
|
@ -21,7 +21,6 @@ DWORD g_muteControlID;
|
||||||
UINT g_mmDeviceChange;
|
UINT g_mmDeviceChange;
|
||||||
|
|
||||||
static BOOL g_IsMute = FALSE;
|
static BOOL g_IsMute = FALSE;
|
||||||
static BOOL g_IsRunning = FALSE;
|
|
||||||
|
|
||||||
static HRESULT __stdcall Volume_FindMixerControl(CSysTray * pSysTray)
|
static HRESULT __stdcall Volume_FindMixerControl(CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
|
@ -156,8 +155,6 @@ HRESULT STDMETHODCALLTYPE Volume_Init(_In_ CSysTray * pSysTray)
|
||||||
|
|
||||||
Volume_IsMute();
|
Volume_IsMute();
|
||||||
|
|
||||||
g_IsRunning = TRUE;
|
|
||||||
|
|
||||||
HICON icon;
|
HICON icon;
|
||||||
if (g_IsMute)
|
if (g_IsMute)
|
||||||
icon = g_hIconMute;
|
icon = g_hIconMute;
|
||||||
|
@ -204,8 +201,6 @@ HRESULT STDMETHODCALLTYPE Volume_Shutdown(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
TRACE("Volume_Shutdown\n");
|
TRACE("Volume_Shutdown\n");
|
||||||
|
|
||||||
g_IsRunning = FALSE;
|
|
||||||
|
|
||||||
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_VOLUME, NULL, NULL);
|
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_VOLUME, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,20 +262,26 @@ HRESULT STDMETHODCALLTYPE Volume_Message(_In_ CSysTray * pSysTray, UINT uMsg, WP
|
||||||
{
|
{
|
||||||
case WM_USER + 220:
|
case WM_USER + 220:
|
||||||
TRACE("Volume_Message: WM_USER+220\n");
|
TRACE("Volume_Message: WM_USER+220\n");
|
||||||
if (wParam == 4)
|
if (wParam == VOLUME_SERVICE_FLAG)
|
||||||
{
|
{
|
||||||
if (lParam == FALSE)
|
if (lParam)
|
||||||
|
{
|
||||||
|
pSysTray->EnableService(VOLUME_SERVICE_FLAG, TRUE);
|
||||||
return Volume_Init(pSysTray);
|
return Volume_Init(pSysTray);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
pSysTray->EnableService(VOLUME_SERVICE_FLAG, FALSE);
|
||||||
return Volume_Shutdown(pSysTray);
|
return Volume_Shutdown(pSysTray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
||||||
case WM_USER + 221:
|
case WM_USER + 221:
|
||||||
TRACE("Volume_Message: WM_USER+221\n");
|
TRACE("Volume_Message: WM_USER+221\n");
|
||||||
if (wParam == 4)
|
if (wParam == VOLUME_SERVICE_FLAG)
|
||||||
{
|
{
|
||||||
lResult = (LRESULT)g_IsRunning;
|
lResult = (LRESULT)pSysTray->IsServiceEnabled(VOLUME_SERVICE_FLAG);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue