From b421d735af100e4ed363734499871941df2791e5 Mon Sep 17 00:00:00 2001 From: Shriraj Sawant Date: Fri, 28 Jul 2017 17:33:38 +0000 Subject: [PATCH] [STOBJECT] -Added hotplug.cpp for handling removable devices notification icon. -Modified CMakeLists.txt et al to plugin this hotplug to stobject. -Added basic code to test the hotplug icon and integrate it with stobject. -Tested in xpvm, needs further testing. svn path=/branches/GSoC_2017/shellext/; revision=75431 --- reactos/dll/shellext/stobject/CMakeLists.txt | 1 + reactos/dll/shellext/stobject/csystray.cpp | 3 +- reactos/dll/shellext/stobject/hotplug.cpp | 137 +++++++++++++++++++ reactos/dll/shellext/stobject/precomp.h | 6 + 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 reactos/dll/shellext/stobject/hotplug.cpp diff --git a/reactos/dll/shellext/stobject/CMakeLists.txt b/reactos/dll/shellext/stobject/CMakeLists.txt index 41f952a634d..3f8f7e1ffca 100644 --- a/reactos/dll/shellext/stobject/CMakeLists.txt +++ b/reactos/dll/shellext/stobject/CMakeLists.txt @@ -23,6 +23,7 @@ add_library(stobject SHARED stobject.rc power.cpp volume.cpp + hotplug.cpp ${CMAKE_CURRENT_BINARY_DIR}/stobject.def) set_module_type(stobject win32dll UNICODE) diff --git a/reactos/dll/shellext/stobject/csystray.cpp b/reactos/dll/shellext/stobject/csystray.cpp index 7fe3ace1fb7..41ddbb5f8cc 100644 --- a/reactos/dll/shellext/stobject/csystray.cpp +++ b/reactos/dll/shellext/stobject/csystray.cpp @@ -12,7 +12,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(stobject); SysTrayIconHandlers_t g_IconHandlers [] = { { Volume_Init, Volume_Shutdown, Volume_Update, Volume_Message }, - { Power_Init, Power_Shutdown, Power_Update, Power_Message } + { Power_Init, Power_Shutdown, Power_Update, Power_Message }, + { Hotplug_Init, Hotplug_Shutdown, Hotplug_Update, Hotplug_Message } }; const int g_NumIcons = _countof(g_IconHandlers); diff --git a/reactos/dll/shellext/stobject/hotplug.cpp b/reactos/dll/shellext/stobject/hotplug.cpp new file mode 100644 index 00000000000..230940b6caf --- /dev/null +++ b/reactos/dll/shellext/stobject/hotplug.cpp @@ -0,0 +1,137 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: dll/shellext/stobject/hotplug.cpp + * PURPOSE: Removable devices notification icon handler + * PROGRAMMERS: Shriraj Sawant a.k.a SR13 + */ + +#include "precomp.h" +#include +#include +#include + +WINE_DEFAULT_DEBUG_CHANNEL(stobject); + +static HICON g_hIconHotplug = NULL; +static LPWSTR g_strTooltip = L"Safely Remove Hardware and Eject Media"; +static BOOL g_IsRunning = FALSE; + +HRESULT STDMETHODCALLTYPE Hotplug_Init(_In_ CSysTray * pSysTray) +{ + TRACE("Hotplug_Init\n"); + g_hIconHotplug = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_EXTRACT)); + g_IsRunning = TRUE; + + return pSysTray->NotifyIcon(NIM_ADD, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip); +} + +HRESULT STDMETHODCALLTYPE Hotplug_Update(_In_ CSysTray * pSysTray) +{ + TRACE("Hotplug_Update\n"); + //g_hIconHotplug = DynamicLoadIcon(g_hInstance); + + return pSysTray->NotifyIcon(NIM_MODIFY, ID_ICON_HOTPLUG, g_hIconHotplug, g_strTooltip); +} + +HRESULT STDMETHODCALLTYPE Hotplug_Shutdown(_In_ CSysTray * pSysTray) +{ + TRACE("Hotplug_Shutdown\n"); + g_IsRunning = FALSE; + + return pSysTray->NotifyIcon(NIM_DELETE, ID_ICON_HOTPLUG, NULL, NULL); +} + +static void _RunHotplug() +{ + ShellExecuteW(NULL, NULL, L"hotplug.cpl", NULL, NULL, SW_SHOWNORMAL); +} + +static void _ShowContextMenu(CSysTray * pSysTray) +{ + CString strOpen((LPCSTR)IDS_HOTPLUG_REMOVE_2); + HMENU hPopup = CreatePopupMenu(); + AppendMenuW(hPopup, MF_STRING, IDS_HOTPLUG_REMOVE_2, strOpen); + + SetForegroundWindow(pSysTray->GetHWnd()); + DWORD flags = TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTALIGN | TPM_BOTTOMALIGN; + POINT pt; + GetCursorPos(&pt); + + DWORD id = TrackPopupMenuEx(hPopup, flags, + pt.x, pt.y, + pSysTray->GetHWnd(), NULL); + + switch (id) + { + case IDS_HOTPLUG_REMOVE_2: + _RunHotplug(); + break; + } + DestroyMenu(hPopup); +} + +HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult) +{ + TRACE("Hotplug_Message uMsg=%d, wParam=%x, lParam=%x\n", uMsg, wParam, lParam); + + switch (uMsg) + { + case WM_USER + 220: + TRACE("Hotplug_Message: WM_USER+220\n"); + if (wParam == 1) + { + if (lParam == FALSE) + return Hotplug_Init(pSysTray); + else + return Hotplug_Shutdown(pSysTray); + } + return S_FALSE; + + case WM_USER + 221: + TRACE("Hotplug_Message: WM_USER+221\n"); + if (wParam == 1) + { + lResult = (LRESULT)g_IsRunning; + return S_OK; + } + return S_FALSE; + + case ID_ICON_HOTPLUG: + Hotplug_Update(pSysTray); + + switch (lParam) + { + case WM_LBUTTONDOWN: + break; + + case WM_LBUTTONUP: + MessageBox(0, L"Safely Remove Hardware", L"Test", MB_OKCANCEL | MB_ICONINFORMATION); + break; + + case WM_LBUTTONDBLCLK: + _RunHotplug(); + break; + + case WM_RBUTTONDOWN: + break; + + case WM_RBUTTONUP: + _ShowContextMenu(pSysTray); + break; + + case WM_RBUTTONDBLCLK: + break; + + case WM_MOUSEMOVE: + break; + } + return S_OK; + + default: + TRACE("Hotplug_Message received for unknown ID %d, ignoring.\n"); + return S_FALSE; + } + + return S_FALSE; +} diff --git a/reactos/dll/shellext/stobject/precomp.h b/reactos/dll/shellext/stobject/precomp.h index 66790be94b4..56db9df7d39 100644 --- a/reactos/dll/shellext/stobject/precomp.h +++ b/reactos/dll/shellext/stobject/precomp.h @@ -40,6 +40,7 @@ extern HINSTANCE g_hInstance; #define ID_ICON_VOLUME (WM_APP + 0x4CB) #define ID_ICON_POWER (WM_APP + 0x4CC) +#define ID_ICON_HOTPLUG (WM_APP + 0x4CD) #include "csystray.h" @@ -70,3 +71,8 @@ extern HRESULT STDMETHODCALLTYPE Power_Init(_In_ CSysTray * pSysTray); extern HRESULT STDMETHODCALLTYPE Power_Shutdown(_In_ CSysTray * pSysTray); extern HRESULT STDMETHODCALLTYPE Power_Update(_In_ CSysTray * pSysTray); extern HRESULT STDMETHODCALLTYPE Power_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult); + +extern HRESULT STDMETHODCALLTYPE Hotplug_Init(_In_ CSysTray * pSysTray); +extern HRESULT STDMETHODCALLTYPE Hotplug_Shutdown(_In_ CSysTray * pSysTray); +extern HRESULT STDMETHODCALLTYPE Hotplug_Update(_In_ CSysTray * pSysTray); +extern HRESULT STDMETHODCALLTYPE Hotplug_Message(_In_ CSysTray * pSysTray, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult);