[HOTPLUG] Add device properties dialog support (#5812)

Clicking at "Properties" button or right-click menu now opens properties dialog for the selected device.
This commit is contained in:
Thamatip Chitpong 2023-10-23 18:53:08 +07:00 committed by GitHub
parent 6f86e11aa2
commit 7f5c59a0b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -157,13 +157,13 @@ InsertDeviceTreeItem(
tvItem.hParent = hParent;
tvItem.hInsertAfter = TVI_LAST;
tvItem.item.mask = TVIF_STATE | TVIF_TEXT /*| TVIF_PARAM*/ | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvItem.item.mask = TVIF_STATE | TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvItem.item.state = TVIS_EXPANDED;
tvItem.item.stateMask = TVIS_EXPANDED;
tvItem.item.pszText = szDisplayName;
tvItem.item.iImage = nClassImage;
tvItem.item.iSelectedImage = nClassImage;
tvItem.item.lParam = (LPARAM)NULL;
tvItem.item.lParam = (LPARAM)DevInst;
return TreeView_InsertItem(hwndDeviceTree, &tvItem);
}
@ -344,6 +344,69 @@ ShowContextMenu(
}
static
DEVINST
GetSelectedDeviceInst(
_In_ HWND hwndDeviceTree)
{
HTREEITEM hTreeItem;
TVITEMW item;
hTreeItem = TreeView_GetSelection(hwndDeviceTree);
if (hTreeItem == NULL)
return 0;
ZeroMemory(&item, sizeof(item));
item.mask = TVIF_PARAM;
item.hItem = hTreeItem;
TreeView_GetItem(hwndDeviceTree, &item);
return item.lParam;
}
static
VOID
ShowDeviceProperties(
_In_ HWND hwndParent,
_In_ DEVINST DevInst)
{
ULONG ulSize;
CONFIGRET cr;
LPWSTR pszDevId;
cr = CM_Get_Device_ID_Size(&ulSize, DevInst, 0);
if (cr != CR_SUCCESS || ulSize == 0)
return;
/* Take the terminating NULL into account */
ulSize++;
pszDevId = HeapAlloc(GetProcessHeap(), 0, ulSize * sizeof(WCHAR));
if (pszDevId == NULL)
return;
cr = CM_Get_Device_IDW(DevInst, pszDevId, ulSize, 0);
if (cr == CR_SUCCESS)
{
typedef int (WINAPI *PFDEVICEPROPERTIESW)(HWND, LPCWSTR, LPCWSTR, BOOL);
HMODULE hDevMgrDll;
PFDEVICEPROPERTIESW pDevicePropertiesW;
hDevMgrDll = LoadLibraryW(L"devmgr.dll");
if (hDevMgrDll != NULL)
{
pDevicePropertiesW = (PFDEVICEPROPERTIESW)GetProcAddress(hDevMgrDll, "DevicePropertiesW");
if (pDevicePropertiesW != NULL)
pDevicePropertiesW(hwndParent, NULL, pszDevId, FALSE);
FreeLibrary(hDevMgrDll);
}
}
HeapFree(GetProcessHeap(), 0, pszDevId);
}
INT_PTR
CALLBACK
SafeRemovalDlgProc(
@ -434,6 +497,14 @@ SafeRemovalDlgProc(
}
}
break;
case IDC_SAFE_REMOVE_PROPERTIES:
case IDM_PROPERTIES:
{
HWND hwndDevTree = GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_DEVICE_TREE);
ShowDeviceProperties(hwndDlg, GetSelectedDeviceInst(hwndDevTree));
break;
}
}
break;