mirror of
https://github.com/reactos/reactos.git
synced 2024-07-01 02:10: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
|
@ -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));
|
||||
|
@ -48,11 +113,14 @@ HRESULT CSysTray::InitIcons()
|
|||
{
|
||||
TRACE("Initializing Notification icons...\n");
|
||||
for (int i = 0; i < g_NumIcons; i++)
|
||||
{
|
||||
if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
|
||||
{
|
||||
HRESULT hr = g_IconHandlers[i].pfnInit(this);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
|
||||
return InitNetShell();
|
||||
}
|
||||
|
@ -61,11 +129,14 @@ HRESULT CSysTray::ShutdownIcons()
|
|||
{
|
||||
TRACE("Shutting down Notification icons...\n");
|
||||
for (int i = 0; i < g_NumIcons; i++)
|
||||
{
|
||||
if (this->dwServicesEnabled & g_IconHandlers[i].dwServiceFlag)
|
||||
{
|
||||
HRESULT hr = g_IconHandlers[i].pfnShutdown(this);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
|
||||
return ShutdownNetShell();
|
||||
}
|
||||
|
@ -74,11 +145,14 @@ HRESULT CSysTray::UpdateIcons()
|
|||
{
|
||||
TRACE("Updating Notification icons...\n");
|
||||
for (int i = 0; i < g_NumIcons; i++)
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue