Author: ssawant Date: Fri Jul 28 17:33:38 2017 New Revision: 75431
URL: http://svn.reactos.org/svn/reactos?rev=75431&view=rev Log: [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.
Added: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/hotplug.cpp (with props) Modified: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/CMakeLists.txt branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/csystray.cpp branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/precomp.h
Modified: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2017/shellext/reactos/dll/s... ============================================================================== --- branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/CMakeLists.txt [iso-8859-1] (original) +++ branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/CMakeLists.txt [iso-8859-1] Fri Jul 28 17:33:38 2017 @@ -23,6 +23,7 @@ stobject.rc power.cpp volume.cpp + hotplug.cpp ${CMAKE_CURRENT_BINARY_DIR}/stobject.def)
set_module_type(stobject win32dll UNICODE)
Modified: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/csystray.cpp URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2017/shellext/reactos/dll/s... ============================================================================== --- branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/csystray.cpp [iso-8859-1] (original) +++ branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/csystray.cpp [iso-8859-1] Fri Jul 28 17:33:38 2017 @@ -12,7 +12,8 @@
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);
Added: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/hotplug.cpp URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2017/shellext/reactos/dll/s... ============================================================================== --- branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/hotplug.cpp (added) +++ branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/hotplug.cpp [iso-8859-1] Fri Jul 28 17:33:38 2017 @@ -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 sr.official@hotmail.com + */ + +#include "precomp.h" +#include <mmsystem.h> +#include <mmddk.h> +#include <atlstr.h> + +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; +}
Propchange: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/hotplug.cpp ------------------------------------------------------------------------------ svn:eol-style = native
Modified: branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/precomp.h URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2017/shellext/reactos/dll/s... ============================================================================== --- branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/precomp.h [iso-8859-1] (original) +++ branches/GSoC_2017/shellext/reactos/dll/shellext/stobject/precomp.h [iso-8859-1] Fri Jul 28 17:33:38 2017 @@ -40,6 +40,7 @@
#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_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);