mirror of
https://github.com/reactos/reactos.git
synced 2025-08-07 13:23:10 +00:00
[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.
This commit is contained in:
parent
93e72ed3d6
commit
fc999e18af
3 changed files with 38 additions and 14 deletions
|
@ -27,8 +27,8 @@ VOID CSysTray::GetServicesEnabled()
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
DWORD dwSize;
|
DWORD dwSize;
|
||||||
|
|
||||||
/* Enable power and volume by default */
|
/* Enable power, volume and hotplug by default */
|
||||||
this->dwServicesEnabled = POWER_SERVICE_FLAG | VOLUME_SERVICE_FLAG;
|
this->dwServicesEnabled = POWER_SERVICE_FLAG | VOLUME_SERVICE_FLAG | HOTPLUG_SERVICE_FLAG;
|
||||||
|
|
||||||
if (RegCreateKeyExW(HKEY_CURRENT_USER,
|
if (RegCreateKeyExW(HKEY_CURRENT_USER,
|
||||||
L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\SysTray",
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\SysTray",
|
||||||
|
|
|
@ -128,28 +128,32 @@ HRESULT NotifyBalloon(CSysTray* pSysTray, LPCWSTR szTitle = NULL, LPCWSTR szInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE Hotplug_Init(_In_ CSysTray * pSysTray)
|
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));
|
||||||
|
|
||||||
EnumHotpluggedDevices(g_devList);
|
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)
|
HRESULT STDMETHODCALLTYPE Hotplug_Update(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
TRACE("Hotplug_Update\n");
|
TRACE("Hotplug_Update\n");
|
||||||
|
return S_OK;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE Hotplug_Shutdown(_In_ CSysTray * pSysTray)
|
HRESULT STDMETHODCALLTYPE Hotplug_Shutdown(_In_ CSysTray * pSysTray)
|
||||||
{
|
{
|
||||||
TRACE("Hotplug_Shutdown\n");
|
TRACE("Hotplug_Shutdown\n");
|
||||||
|
|
||||||
|
DestroyIcon(g_hIconHotplug);
|
||||||
|
g_hIconHotplug = NULL;
|
||||||
|
|
||||||
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_HOTPLUG, NULL, NULL);
|
return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_HOTPLUG, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,9 +243,24 @@ static void _ShowContextMenuR(CSysTray * pSysTray)
|
||||||
DestroyMenu(hPopup);
|
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 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);
|
TRACE("Hotplug_Message uMsg=%d, wParam=%x, lParam=%x\n", uMsg, wParam, lParam);
|
||||||
|
|
||||||
switch (uMsg)
|
switch (uMsg)
|
||||||
|
@ -294,6 +313,11 @@ HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray, UINT uMsg, W
|
||||||
KillTimer(pSysTray->GetHWnd(), HOTPLUG_TIMER_ID);
|
KillTimer(pSysTray->GetHWnd(), HOTPLUG_TIMER_ID);
|
||||||
_ShowContextMenu(pSysTray);
|
_ShowContextMenu(pSysTray);
|
||||||
}
|
}
|
||||||
|
else if (wParam == HOTPLUG_DEVICE_TIMER_ID)
|
||||||
|
{
|
||||||
|
KillTimer(pSysTray->GetHWnd(), HOTPLUG_DEVICE_TIMER_ID);
|
||||||
|
HotplugDeviceTimer(pSysTray);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_ICON_HOTPLUG:
|
case ID_ICON_HOTPLUG:
|
||||||
|
@ -332,12 +356,11 @@ HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray, UINT uMsg, W
|
||||||
switch (wParam)
|
switch (wParam)
|
||||||
{
|
{
|
||||||
case DBT_DEVNODES_CHANGED:
|
case DBT_DEVNODES_CHANGED:
|
||||||
hr = EnumHotpluggedDevices(g_devList);
|
TRACE("WM_DEVICECHANGE : DBT_DEVNODES_CHANGED\n");
|
||||||
if (FAILED(hr))
|
SetTimer(pSysTray->GetHWnd(), HOTPLUG_DEVICE_TIMER_ID, 100, NULL);
|
||||||
return hr;
|
|
||||||
|
|
||||||
lResult = true;
|
lResult = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DBT_DEVICEARRIVAL:
|
case DBT_DEVICEARRIVAL:
|
||||||
break;
|
break;
|
||||||
case DBT_DEVICEQUERYREMOVE:
|
case DBT_DEVICEQUERYREMOVE:
|
||||||
|
|
|
@ -77,5 +77,6 @@ extern HRESULT STDMETHODCALLTYPE Power_Message(_In_ CSysTray * pSysTray, UINT uM
|
||||||
#define POWER_TIMER_ID 2
|
#define POWER_TIMER_ID 2
|
||||||
#define VOLUME_TIMER_ID 3
|
#define VOLUME_TIMER_ID 3
|
||||||
#define HOTPLUG_TIMER_ID 4
|
#define HOTPLUG_TIMER_ID 4
|
||||||
|
#define HOTPLUG_DEVICE_TIMER_ID 5
|
||||||
|
|
||||||
#endif /* _STOBJECT_PRECOMP_H_ */
|
#endif /* _STOBJECT_PRECOMP_H_ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue