https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fc999e18af4e57f66cde7…
commit fc999e18af4e57f66cde7845cfbac7692e13384d
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sat Mar 21 23:46:24 2020 +0100
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sat Mar 21 23:46:24 2020 +0100
[STDOBJECT] Show the hotplug icon when a USB-Stick is inserted
- Enable the hotplug service by default
- Start a timer on WM_DEVICECHANGE:DBT_DEVNODES_CHANGED to trigger the removable
device detection.
---
dll/shellext/stobject/csystray.cpp | 4 ++--
dll/shellext/stobject/hotplug.cpp | 47 ++++++++++++++++++++++++++++----------
dll/shellext/stobject/precomp.h | 1 +
3 files changed, 38 insertions(+), 14 deletions(-)
diff --git a/dll/shellext/stobject/csystray.cpp b/dll/shellext/stobject/csystray.cpp
index 136927896bf..14f9c213a9f 100644
--- a/dll/shellext/stobject/csystray.cpp
+++ b/dll/shellext/stobject/csystray.cpp
@@ -27,8 +27,8 @@ VOID CSysTray::GetServicesEnabled()
HKEY hKey;
DWORD dwSize;
- /* Enable power and volume by default */
- this->dwServicesEnabled = POWER_SERVICE_FLAG | VOLUME_SERVICE_FLAG;
+ /* Enable power, volume and hotplug by default */
+ this->dwServicesEnabled = POWER_SERVICE_FLAG | VOLUME_SERVICE_FLAG |
HOTPLUG_SERVICE_FLAG;
if (RegCreateKeyExW(HKEY_CURRENT_USER,
L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\SysTray",
diff --git a/dll/shellext/stobject/hotplug.cpp b/dll/shellext/stobject/hotplug.cpp
index b2202c99d44..5df143d8454 100644
--- a/dll/shellext/stobject/hotplug.cpp
+++ b/dll/shellext/stobject/hotplug.cpp
@@ -128,28 +128,32 @@ HRESULT NotifyBalloon(CSysTray* pSysTray, LPCWSTR szTitle = NULL,
LPCWSTR szInfo
}
HRESULT STDMETHODCALLTYPE Hotplug_Init(_In_ CSysTray * pSysTray)
-{
+{
TRACE("Hotplug_Init\n");
+
g_hIconHotplug = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_HOTPLUG_OK));
+
EnumHotpluggedDevices(g_devList);
- return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug,
g_strTooltip, NIS_HIDDEN);
+ if (g_devList.GetSize() > 0)
+ return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug,
g_strTooltip);
+ else
+ return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug,
g_strTooltip, NIS_HIDDEN);
}
HRESULT STDMETHODCALLTYPE Hotplug_Update(_In_ CSysTray * pSysTray)
{
TRACE("Hotplug_Update\n");
-
- if(g_devList.GetSize() || g_IsRemoving)
- return pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug,
g_strTooltip);
- else
- return pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug,
g_strTooltip, NIS_HIDDEN);
+ return S_OK;
}
HRESULT STDMETHODCALLTYPE Hotplug_Shutdown(_In_ CSysTray * pSysTray)
{
TRACE("Hotplug_Shutdown\n");
+ DestroyIcon(g_hIconHotplug);
+ g_hIconHotplug = NULL;
+
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_HOTPLUG, NULL, NULL);
}
@@ -239,9 +243,24 @@ static void _ShowContextMenuR(CSysTray * pSysTray)
DestroyMenu(hPopup);
}
+
+VOID
+HotplugDeviceTimer(
+ _In_ CSysTray *pSysTray)
+{
+ TRACE("HotplugDeviceTimer()\n");
+
+ EnumHotpluggedDevices(g_devList);
+
+ if (g_devList.GetSize() > 0)
+ pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug,
g_strTooltip);
+ else
+ pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug,
g_strTooltip, NIS_HIDDEN);
+}
+
+
HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPARAM
wParam, LPARAM lParam, LRESULT &lResult)
{
- HRESULT hr = E_FAIL;
TRACE("Hotplug_Message uMsg=%d, wParam=%x, lParam=%x\n", uMsg, wParam,
lParam);
switch (uMsg)
@@ -294,6 +313,11 @@ HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray,
UINT uMsg, W
KillTimer(pSysTray->GetHWnd(), HOTPLUG_TIMER_ID);
_ShowContextMenu(pSysTray);
}
+ else if (wParam == HOTPLUG_DEVICE_TIMER_ID)
+ {
+ KillTimer(pSysTray->GetHWnd(), HOTPLUG_DEVICE_TIMER_ID);
+ HotplugDeviceTimer(pSysTray);
+ }
break;
case ID_ICON_HOTPLUG:
@@ -332,12 +356,11 @@ HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray,
UINT uMsg, W
switch (wParam)
{
case DBT_DEVNODES_CHANGED:
- hr = EnumHotpluggedDevices(g_devList);
- if (FAILED(hr))
- return hr;
-
+ TRACE("WM_DEVICECHANGE : DBT_DEVNODES_CHANGED\n");
+ SetTimer(pSysTray->GetHWnd(), HOTPLUG_DEVICE_TIMER_ID, 100,
NULL);
lResult = true;
break;
+
case DBT_DEVICEARRIVAL:
break;
case DBT_DEVICEQUERYREMOVE:
diff --git a/dll/shellext/stobject/precomp.h b/dll/shellext/stobject/precomp.h
index 87747a90b49..e60b0a265b8 100644
--- a/dll/shellext/stobject/precomp.h
+++ b/dll/shellext/stobject/precomp.h
@@ -77,5 +77,6 @@ extern HRESULT STDMETHODCALLTYPE Power_Message(_In_ CSysTray * pSysTray,
UINT uM
#define POWER_TIMER_ID 2
#define VOLUME_TIMER_ID 3
#define HOTPLUG_TIMER_ID 4
+#define HOTPLUG_DEVICE_TIMER_ID 5
#endif /* _STOBJECT_PRECOMP_H_ */