diff --git a/dll/cpl/hotplug/CMakeLists.txt b/dll/cpl/hotplug/CMakeLists.txt index ec6588697c511..c5e636d8938f7 100644 --- a/dll/cpl/hotplug/CMakeLists.txt +++ b/dll/cpl/hotplug/CMakeLists.txt @@ -3,6 +3,7 @@ spec2def(hotplug.dll hotplug.spec) list(APPEND SOURCE hotplug.c + eject.c enum.c) file(GLOB hotplug_rc_deps resources/*.*) diff --git a/dll/cpl/hotplug/eject.c b/dll/cpl/hotplug/eject.c new file mode 100644 index 0000000000000..5d45ec506eddc --- /dev/null +++ b/dll/cpl/hotplug/eject.c @@ -0,0 +1,63 @@ +/* + * PROJECT: ReactOS Safely Remove Hardware Applet + * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) + * PURPOSE: Hardware safe removal support + * COPYRIGHT: Copyright 2023 Thamatip Chitpong + */ + +#include "hotplug.h" + +static +VOID +SafeRemoveDevice( + _In_ DEVINST DevInst) +{ + PNP_VETO_TYPE VetoType = PNP_VetoTypeUnknown; + CONFIGRET cr; + + cr = CM_Request_Device_EjectW(DevInst, &VetoType, NULL, 0, 0); + if (cr != CR_SUCCESS && VetoType == PNP_VetoTypeUnknown) + { + WCHAR szError[64]; + swprintf(szError, L"Failed to remove device (0x%x)", cr); + MessageBoxW(NULL, szError, NULL, MB_ICONEXCLAMATION | MB_OK); + } +} + +INT_PTR +CALLBACK +ConfirmRemovalDlgProc( + HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) +{ + static DEVINST selectedDev; + + switch (uMsg) + { + case WM_INITDIALOG: + selectedDev = lParam; + return TRUE; + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDCANCEL: + case IDCLOSE: + EndDialog(hwndDlg, TRUE); + break; + + case IDOK: + SafeRemoveDevice(selectedDev); + EndDialog(hwndDlg, TRUE); + break; + } + + break; + } + } + + return FALSE; +} diff --git a/dll/cpl/hotplug/hotplug.c b/dll/cpl/hotplug/hotplug.c index 6d82b560637f0..a74728abf99a0 100644 --- a/dll/cpl/hotplug/hotplug.c +++ b/dll/cpl/hotplug/hotplug.c @@ -407,23 +407,6 @@ ShowDeviceProperties( HeapFree(GetProcessHeap(), 0, pszDevId); } -static -VOID -SafeRemoveDevice( - _In_ DEVINST DevInst) -{ - PNP_VETO_TYPE VetoType = PNP_VetoTypeUnknown; - CONFIGRET cr; - - cr = CM_Request_Device_EjectW(DevInst, &VetoType, NULL, 0, 0); - if (cr != CR_SUCCESS && VetoType == PNP_VetoTypeUnknown) - { - WCHAR szError[64]; - swprintf(szError, L"Failed to remove device (0x%x)", cr); - MessageBoxW(NULL, szError, NULL, MB_ICONEXCLAMATION | MB_OK); - } -} - INT_PTR CALLBACK SafeRemovalDlgProc( @@ -527,7 +510,11 @@ SafeRemovalDlgProc( case IDM_STOP: { HWND hwndDevTree = GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_DEVICE_TREE); - SafeRemoveDevice(GetSelectedDeviceInst(hwndDevTree)); + DialogBoxParamW(hApplet, + MAKEINTRESOURCEW(IDD_CONFIRM_STOP_HARDWARE_DIALOG), + hwndDlg, + ConfirmRemovalDlgProc, + (LPARAM)GetSelectedDeviceInst(hwndDevTree)); break; } } diff --git a/dll/cpl/hotplug/hotplug.h b/dll/cpl/hotplug/hotplug.h index 8e11875c61362..47cf851b93a9a 100644 --- a/dll/cpl/hotplug/hotplug.h +++ b/dll/cpl/hotplug/hotplug.h @@ -39,6 +39,14 @@ typedef struct }APPLET, *PAPPLET; +// eject.c +INT_PTR +CALLBACK +ConfirmRemovalDlgProc( + HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); // hotplug.c LONG diff --git a/dll/cpl/hotplug/lang/en-US.rc b/dll/cpl/hotplug/lang/en-US.rc index f0728860bba80..fc6cc0c9f1997 100644 --- a/dll/cpl/hotplug/lang/en-US.rc +++ b/dll/cpl/hotplug/lang/en-US.rc @@ -17,6 +17,18 @@ BEGIN PUSHBUTTON "&Close", IDCLOSE, 216, 224, 55, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP END +IDD_CONFIRM_STOP_HARDWARE_DIALOG DIALOGEX 32, 10, 256, 148 +CAPTION "Stop a Hardware Device" +STYLE DS_SHELLFONT | DS_MODALFRAME | DS_SETFOREGROUND | WS_POPUP | WS_CAPTION | WS_SYSMENU +FONT 8, "MS Shell Dlg" +BEGIN + LTEXT "ReactOS will attempt to stop the following devices. After the devices are stopped they may be removed safely.", IDC_STATIC, 7, 8, 240, 18, WS_CHILD | WS_VISIBLE | WS_GROUP + LTEXT "Choose OK to continue.", IDC_STATIC, 7, 32, 240, 18, WS_CHILD | WS_VISIBLE | WS_GROUP + CONTROL "", IDC_CONFIRM_STOP_DEVICE_LIST, "SysListView32", LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_SHAREIMAGELISTS | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_GROUP | WS_TABSTOP, 8, 45, 240, 78 + DEFPUSHBUTTON "OK", IDOK, 144, 127, 50, 14 + PUSHBUTTON "Cancel", IDCANCEL, 198, 127, 50, 14 +END + /* Menus */ diff --git a/dll/cpl/hotplug/resource.h b/dll/cpl/hotplug/resource.h index af8d359670db3..e848a0f926ae2 100644 --- a/dll/cpl/hotplug/resource.h +++ b/dll/cpl/hotplug/resource.h @@ -15,6 +15,7 @@ #define IDC_SAFE_REMOVE_DISPLAY_COMPONENTS 306 #define IDD_CONFIRM_STOP_HARDWARE_DIALOG 310 +#define IDC_CONFIRM_STOP_DEVICE_LIST 311 /* Menu IDs */ #define IDM_POPUP_DEVICE_TREE 500