mirror of
https://github.com/reactos/reactos.git
synced 2024-07-01 18:24:24 +00:00
[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
This commit is contained in:
parent
d13b13ec76
commit
b421d735af
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
137
reactos/dll/shellext/stobject/hotplug.cpp
Normal file
137
reactos/dll/shellext/stobject/hotplug.cpp
Normal file
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue