https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8c30fdab1c42af81800e2…
commit 8c30fdab1c42af81800e2ba7b68845192a9cae92
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Tue Apr 23 00:12:23 2019 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Tue Apr 23 00:12:23 2019 +0200
[STOBJECT] Store the "Show x icon in the taskbar" setting for the hotplug,
power and volume icons.
CORE-12365
CORE-12972
CORE-15234
---
dll/shellext/stobject/csystray.cpp | 99 +++++++++++++++++++++++++++++++++-----
dll/shellext/stobject/csystray.h | 6 +++
dll/shellext/stobject/hotplug.cpp | 18 ++++---
dll/shellext/stobject/power.cpp | 17 ++++---
dll/shellext/stobject/precomp.h | 5 ++
dll/shellext/stobject/volume.cpp | 19 ++++----
6 files changed, 128 insertions(+), 36 deletions(-)
diff --git a/dll/shellext/stobject/csystray.cpp b/dll/shellext/stobject/csystray.cpp
index d73e67e55d..136927896b 100644
--- a/dll/shellext/stobject/csystray.cpp
+++ b/dll/shellext/stobject/csystray.cpp
@@ -13,15 +13,80 @@
#include <shellutils.h>
SysTrayIconHandlers_t g_IconHandlers [] = {
- { Volume_Init, Volume_Shutdown, Volume_Update, Volume_Message },
- { Hotplug_Init, Hotplug_Shutdown, Hotplug_Update, Hotplug_Message },
- { Power_Init, Power_Shutdown, Power_Update, Power_Message }
+ { VOLUME_SERVICE_FLAG, Volume_Init, Volume_Shutdown, Volume_Update, Volume_Message
},
+ { HOTPLUG_SERVICE_FLAG, Hotplug_Init, Hotplug_Shutdown, Hotplug_Update,
Hotplug_Message },
+ { POWER_SERVICE_FLAG, Power_Init, Power_Shutdown, Power_Update, Power_Message }
};
const int g_NumIcons = _countof(g_IconHandlers);
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 hr = CoCreateInstance(CLSID_ConnectionTray, 0, 1u,
IID_PPV_ARG(IOleCommandTarget, &pctNetShell));
@@ -49,9 +114,12 @@ HRESULT CSysTray::InitIcons()
TRACE("Initializing Notification icons...\n");
for (int i = 0; i < g_NumIcons; i++)
{
- HRESULT hr = g_IconHandlers[i].pfnInit(this);
- if (FAILED(hr))
- return hr;
+ if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
+ {
+ HRESULT hr = g_IconHandlers[i].pfnInit(this);
+ if (FAILED(hr))
+ return hr;
+ }
}
return InitNetShell();
@@ -62,9 +130,12 @@ HRESULT CSysTray::ShutdownIcons()
TRACE("Shutting down Notification icons...\n");
for (int i = 0; i < g_NumIcons; i++)
{
- HRESULT hr = g_IconHandlers[i].pfnShutdown(this);
- if (FAILED(hr))
- return hr;
+ if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
+ {
+ HRESULT hr = g_IconHandlers[i].pfnShutdown(this);
+ if (FAILED(hr))
+ return hr;
+ }
}
return ShutdownNetShell();
@@ -75,9 +146,12 @@ HRESULT CSysTray::UpdateIcons()
TRACE("Updating Notification icons...\n");
for (int i = 0; i < g_NumIcons; i++)
{
- HRESULT hr = g_IconHandlers[i].pfnUpdate(this);
- if (FAILED(hr))
- return hr;
+ if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
+ {
+ HRESULT hr = g_IconHandlers[i].pfnUpdate(this);
+ if (FAILED(hr))
+ return hr;
+ }
}
return S_OK;
@@ -236,6 +310,7 @@ BOOL CSysTray::ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM
wParam, LPARAM
return FALSE;
case WM_CREATE:
+ GetServicesEnabled();
InitIcons();
SetTimer(1, 2000, NULL);
return TRUE;
diff --git a/dll/shellext/stobject/csystray.h b/dll/shellext/stobject/csystray.h
index 214a4c6549..0ff5236782 100644
--- a/dll/shellext/stobject/csystray.h
+++ b/dll/shellext/stobject/csystray.h
@@ -28,6 +28,7 @@ class CSysTray :
// TODO: keep icon handlers here
+ DWORD dwServicesEnabled;
HWND hwndSysTray;
static DWORD WINAPI s_SysTrayThreadProc(PVOID param);
@@ -44,11 +45,16 @@ class CSysTray :
HRESULT InitNetShell();
HRESULT ShutdownNetShell();
+ VOID GetServicesEnabled();
+
public:
HRESULT NotifyIcon(INT code, UINT uId, HICON hIcon, LPCWSTR szTip, DWORD dwstate =
0);
HWND GetHWnd() { return m_hWnd; }
+ VOID EnableService(DWORD dwServiceFlag, BOOL bEnable);
+ BOOL IsServiceEnabled(DWORD dwServiceFlag);
+
protected:
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT
&lResult, DWORD dwMsgMapID = 0);
diff --git a/dll/shellext/stobject/hotplug.cpp b/dll/shellext/stobject/hotplug.cpp
index af7d69891b..03348f92d2 100644
--- a/dll/shellext/stobject/hotplug.cpp
+++ b/dll/shellext/stobject/hotplug.cpp
@@ -22,7 +22,6 @@ CSimpleArray<DEVINST> g_devList;
static HICON g_hIconHotplug = NULL;
static LPCWSTR g_strTooltip = L"Safely Remove Hardware and Eject Media";
static WCHAR g_strMenuSel[DISPLAY_NAME_LEN];
-static BOOL g_IsRunning = FALSE;
static BOOL g_IsRemoving = FALSE;
/*++
@@ -132,7 +131,6 @@ HRESULT STDMETHODCALLTYPE Hotplug_Init(_In_ CSysTray * pSysTray)
{
TRACE("Hotplug_Init\n");
g_hIconHotplug = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_HOTPLUG_OK));
- g_IsRunning = TRUE;
EnumHotpluggedDevices(g_devList);
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");
- g_IsRunning = FALSE;
-
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:
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);
+ }
else
+ {
+ pSysTray->EnableService(HOTPLUG_SERVICE_FLAG, FALSE);
return Hotplug_Shutdown(pSysTray);
+ }
}
return S_FALSE;
case WM_USER + 221:
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_FALSE;
diff --git a/dll/shellext/stobject/power.cpp b/dll/shellext/stobject/power.cpp
index 6cb16fdbc9..932dc47dea 100644
--- a/dll/shellext/stobject/power.cpp
+++ b/dll/shellext/stobject/power.cpp
@@ -28,7 +28,6 @@ typedef struct _PWRSCHEMECONTEXT
CString g_strTooltip;
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");
g_hIconBattery = DynamicLoadIcon(g_hInstance);
- g_IsRunning = TRUE;
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)
{
TRACE("Power_Shutdown\n");
- g_IsRunning = FALSE;
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:
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);
+ }
else
+ {
+ pSysTray->EnableService(POWER_SERVICE_FLAG, FALSE);
return Power_Shutdown(pSysTray);
+ }
}
return S_FALSE;
case WM_USER + 221:
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_FALSE;
diff --git a/dll/shellext/stobject/precomp.h b/dll/shellext/stobject/precomp.h
index 674a32ebf0..87747a90b4 100644
--- a/dll/shellext/stobject/precomp.h
+++ b/dll/shellext/stobject/precomp.h
@@ -34,6 +34,10 @@ extern HINSTANCE g_hInstance;
#define ID_ICON_HOTPLUG (WM_APP + 0x4CC)
#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"
typedef HRESULT(STDMETHODCALLTYPE * PFNSTINIT) (_In_ CSysTray * pSysTray);
@@ -43,6 +47,7 @@ typedef HRESULT(STDMETHODCALLTYPE * PFNSTMESSAGE) (_In_ CSysTray *
pSysTray, UI
struct SysTrayIconHandlers_t
{
+ DWORD dwServiceFlag;
PFNSTINIT pfnInit;
PFNSTSHUTDOWN pfnShutdown;
PFNSTUPDATE pfnUpdate;
diff --git a/dll/shellext/stobject/volume.cpp b/dll/shellext/stobject/volume.cpp
index dbc92ad5ce..04723a7be2 100644
--- a/dll/shellext/stobject/volume.cpp
+++ b/dll/shellext/stobject/volume.cpp
@@ -21,7 +21,6 @@ DWORD g_muteControlID;
UINT g_mmDeviceChange;
static BOOL g_IsMute = FALSE;
-static BOOL g_IsRunning = FALSE;
static HRESULT __stdcall Volume_FindMixerControl(CSysTray * pSysTray)
{
@@ -156,8 +155,6 @@ HRESULT STDMETHODCALLTYPE Volume_Init(_In_ CSysTray * pSysTray)
Volume_IsMute();
- g_IsRunning = TRUE;
-
HICON icon;
if (g_IsMute)
icon = g_hIconMute;
@@ -204,8 +201,6 @@ HRESULT STDMETHODCALLTYPE Volume_Shutdown(_In_ CSysTray * pSysTray)
{
TRACE("Volume_Shutdown\n");
- g_IsRunning = FALSE;
-
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:
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);
+ }
else
+ {
+ pSysTray->EnableService(VOLUME_SERVICE_FLAG, FALSE);
return Volume_Shutdown(pSysTray);
+ }
}
return S_FALSE;
case WM_USER + 221:
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_FALSE;