[HOTPLUG] Add the context menu to the device tree view

This commit is contained in:
Eric Kohl 2020-04-05 09:48:14 +02:00
parent 7d1f270918
commit bfdd6261f2
4 changed files with 102 additions and 8 deletions

View file

@ -18,6 +18,7 @@
typedef struct _HOTPLUG_DATA
{
SP_CLASSIMAGELIST_DATA ImageListData;
HMENU hPopupMenu;
DWORD dwFlags;
} HOTPLUG_DATA, *PHOTPLUG_DATA;
@ -234,11 +235,9 @@ EnumHotpluggedDevices(
int idev;
DWORD dwCapabilities, dwSize;
ULONG ulStatus, ulProblem;
HTREEITEM hTreeItem;
CONFIGRET cr;
DPRINT1("EnumHotpluggedDevices()\n");
TreeView_DeleteAllItems(hwndDeviceTree);
@ -299,6 +298,50 @@ EnumHotpluggedDevices(
}
static
VOID
UpdateButtons(
HWND hwndDlg)
{
BOOL bEnabled;
bEnabled = (TreeView_GetCount(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_DEVICE_TREE)) != 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_PROPERTIES), bEnabled);
EnableWindow(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_STOP), bEnabled);
}
static
VOID
ShowContextMenu(
HWND hwndDlg,
HWND hwndTreeView,
PHOTPLUG_DATA pHotplugData)
{
HTREEITEM hTreeItem;
RECT rc;
POINT pt;
hTreeItem = TreeView_GetSelection(hwndTreeView);
if (hTreeItem == NULL)
return;
TreeView_GetItemRect(hwndTreeView, hTreeItem, &rc, TRUE);
pt.x = (rc.left + rc.right) / 2;
pt.y = (rc.top + rc.bottom) / 2;
ClientToScreen(hwndTreeView, &pt);
TrackPopupMenu(GetSubMenu(pHotplugData->hPopupMenu, 0),
TPM_LEFTALIGN | TPM_TOPALIGN,
pt.x,
pt.y,
0,
hwndDlg,
NULL);
}
INT_PTR
CALLBACK
SafeRemovalDlgProc(
@ -309,14 +352,12 @@ SafeRemovalDlgProc(
{
PHOTPLUG_DATA pHotplugData;
UNREFERENCED_PARAMETER(lParam);
pHotplugData = (PHOTPLUG_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
switch (uMsg)
{
case WM_INITDIALOG:
pHotplugData = HeapAlloc(GetProcessHeap(), 0, sizeof(HOTPLUG_DATA));
pHotplugData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HOTPLUG_DATA));
if (pHotplugData != NULL)
{
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pHotplugData);
@ -324,6 +365,8 @@ SafeRemovalDlgProc(
pHotplugData->ImageListData.cbSize = sizeof(pHotplugData->ImageListData);
SetupDiGetClassImageList(&pHotplugData->ImageListData);
pHotplugData->hPopupMenu = LoadMenu(hApplet, MAKEINTRESOURCE(IDM_POPUP_DEVICE_TREE));
pHotplugData->dwFlags = GetHotPlugFlags();
if (pHotplugData->dwFlags & HOTPLUG_DISPLAY_DEVICE_COMPONENTS)
@ -335,6 +378,7 @@ SafeRemovalDlgProc(
EnumHotpluggedDevices(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_DEVICE_TREE),
pHotplugData);
UpdateButtons(hwndDlg);
}
return TRUE;
@ -384,6 +428,23 @@ SafeRemovalDlgProc(
{
EnumHotpluggedDevices(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_DEVICE_TREE),
pHotplugData);
UpdateButtons(hwndDlg);
}
}
break;
case WM_NOTIFY:
if (((LPNMHDR)lParam)->idFrom == IDC_SAFE_REMOVE_DEVICE_TREE)
{
if (((LPNMHDR)lParam)->code == NM_RCLICK)
{
if (pHotplugData != NULL)
{
ShowContextMenu(hwndDlg,
((LPNMHDR)lParam)->hwndFrom,
pHotplugData);
return TRUE;
}
}
}
break;
@ -396,6 +457,9 @@ SafeRemovalDlgProc(
case WM_DESTROY:
if (pHotplugData != NULL)
{
if (pHotplugData->hPopupMenu != NULL)
DestroyMenu(pHotplugData->hPopupMenu);
SetupDiDestroyClassImageList(&pHotplugData->ImageListData);
HeapFree(GetProcessHeap(), 0, pHotplugData);

View file

@ -16,3 +16,15 @@ BEGIN
AUTOCHECKBOX "&Gerätekomponenten anzeigen", IDC_SAFE_REMOVE_DISPLAY_COMPONENTS, 7, 208, 112, 10, WS_CHILD | WS_VISIBLE | WS_TABSTOP
PUSHBUTTON "&Schließen", IDCLOSE, 216, 224, 55, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
END
/* Menus */
IDM_POPUP_DEVICE_TREE MENU
BEGIN
POPUP ""
BEGIN
MENUITEM "Beenden", IDM_STOP
MENUITEM "Eigenschaften", IDM_PROPERTIES
END
END

View file

@ -16,3 +16,15 @@ BEGIN
AUTOCHECKBOX "&Display device components", IDC_SAFE_REMOVE_DISPLAY_COMPONENTS, 7, 208, 112, 10, WS_CHILD | WS_VISIBLE | WS_TABSTOP
PUSHBUTTON "&Close", IDCLOSE, 216, 224, 55, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP
END
/* Menus */
IDM_POPUP_DEVICE_TREE MENU
BEGIN
POPUP ""
BEGIN
MENUITEM "Stop", IDM_STOP
MENUITEM "Properties", IDM_PROPERTIES
END
END

View file

@ -1,9 +1,9 @@
#pragma once
/* Icon ids */
/* Icon IDs */
#define IDI_HOTPLUG 100
/* Dialog ids */
/* Dialog IDs */
#define IDC_STATIC -1
#define IDD_SAFE_REMOVE_HARDWARE_DIALOG 300
@ -16,6 +16,12 @@
#define IDD_CONFIRM_STOP_HARDWARE_DIALOG 310
/* Resource strings ids */
/* Menu IDs */
#define IDM_POPUP_DEVICE_TREE 500
#define IDM_STOP 501
#define IDM_PROPERTIES 502
/* Resource strings IDs */
#define IDS_CPLNAME 1000
#define IDS_CPLDESCRIPTION 1001