[DEVMGMT]

Implement the "Show hidden devices" feature.

svn path=/trunk/; revision=56214
This commit is contained in:
Eric Kohl 2012-03-22 22:38:06 +00:00
parent a0d5e53b32
commit e658cf65ee
24 changed files with 128 additions and 45 deletions

View file

@ -136,11 +136,13 @@ InsertIntoTreeView(HWND hTreeView,
static INT
EnumDeviceClasses(INT ClassIndex,
BOOL ShowHidden,
LPTSTR DevClassName,
LPTSTR DevClassDesc,
BOOL *DevPresent,
INT *ClassImage,
BOOL *IsUnknown)
BOOL *IsUnknown,
BOOL *IsHidden)
{
GUID ClassGuid;
HKEY KeyClass;
@ -150,6 +152,7 @@ EnumDeviceClasses(INT ClassIndex,
*DevPresent = FALSE;
*DevClassName = _T('\0');
*IsHidden = FALSE;
Ret = CM_Enumerate_Classes(ClassIndex,
&ClassGuid,
@ -173,6 +176,11 @@ EnumDeviceClasses(INT ClassIndex,
/* This case is special because these devices don't show up with normal class enumeration */
*IsUnknown = IsEqualGUID(&ClassGuid, &GUID_DEVCLASS_UNKNOWN);
if (ShowHidden == FALSE &&
(IsEqualGUID(&ClassGuid, &GUID_DEVCLASS_LEGACYDRIVER) ||
IsEqualGUID(&ClassGuid, &GUID_DEVCLASS_VOLUME)))
*IsHidden = TRUE;
if (SetupDiClassNameFromGuid(&ClassGuid,
ClassName,
RequiredSize,
@ -327,7 +335,8 @@ EnumDevices(INT index,
VOID
ListDevicesByType(HWND hTreeView,
HTREEITEM hRoot)
HTREEITEM hRoot,
BOOL bShowHidden)
{
HTREEITEM hDevItem;
TCHAR DevName[MAX_DEV_LEN];
@ -338,17 +347,20 @@ ListDevicesByType(HWND hTreeView,
INT index = 0;
INT DevImage;
BOOL IsUnknown = FALSE;
BOOL IsHidden = FALSE;
do
{
ClassRet = EnumDeviceClasses(index,
bShowHidden,
DevName,
DevDesc,
&DevExist,
&DevImage,
&IsUnknown);
&IsUnknown,
&IsHidden);
if ((ClassRet != -1) && (DevExist))
if ((ClassRet != -1) && (DevExist) && !IsHidden)
{
TCHAR DeviceName[MAX_DEV_LEN];
INT DevIndex = 0;
@ -442,7 +454,8 @@ ListDevicesByType(HWND hTreeView,
static HTREEITEM
AddDeviceToTree(HWND hTreeView,
HTREEITEM hRoot,
DEVINST dnDevInst)
DEVINST dnDevInst,
BOOL bShowHidden)
{
TCHAR DevName[MAX_DEV_LEN];
TCHAR FriendlyName[MAX_DEV_LEN];
@ -453,6 +466,28 @@ AddDeviceToTree(HWND hTreeView,
INT ClassImage = 24;
CONFIGRET cr;
ulLength = MAX_GUID_STRING_LEN * sizeof(TCHAR);
cr = CM_Get_DevNode_Registry_Property(dnDevInst,
CM_DRP_CLASSGUID,
NULL,
ClassGuidString,
&ulLength,
0);
if (cr == CR_SUCCESS)
{
pSetupGuidFromString(ClassGuidString, &ClassGuid);
if (bShowHidden == FALSE &&
(IsEqualGUID(&ClassGuid, &GUID_DEVCLASS_LEGACYDRIVER) ||
IsEqualGUID(&ClassGuid, &GUID_DEVCLASS_VOLUME)))
return NULL;
}
else
{
/* It's a device with no driver */
ClassGuid = GUID_DEVCLASS_UNKNOWN;
}
cr = CM_Get_Device_ID(dnDevInst,
DevName,
MAX_DEV_LEN,
@ -480,23 +515,6 @@ AddDeviceToTree(HWND hTreeView,
return NULL;
}
ulLength = MAX_GUID_STRING_LEN * sizeof(TCHAR);
cr = CM_Get_DevNode_Registry_Property(dnDevInst,
CM_DRP_CLASSGUID,
NULL,
ClassGuidString,
&ulLength,
0);
if (cr == CR_SUCCESS)
{
pSetupGuidFromString(ClassGuidString, &ClassGuid);
}
else
{
/* It's a device with no driver */
ClassGuid = GUID_DEVCLASS_UNKNOWN;
}
if (!SetupDiGetClassImageIndex(&ImageListData,
&ClassGuid,
&ClassImage))
@ -532,7 +550,8 @@ AddDeviceToTree(HWND hTreeView,
static VOID
EnumChildDevices(HWND hTreeView,
HTREEITEM hRoot,
DEVINST dnParentDevInst)
DEVINST dnParentDevInst,
BOOL bShowHidden)
{
HTREEITEM hDevItem;
DEVINST dnDevInst;
@ -546,13 +565,15 @@ EnumChildDevices(HWND hTreeView,
hDevItem = AddDeviceToTree(hTreeView,
hRoot,
dnDevInst);
if (hDevItem == NULL)
return;
EnumChildDevices(hTreeView,
hDevItem,
dnDevInst);
dnDevInst,
bShowHidden);
if (hDevItem != NULL)
{
EnumChildDevices(hTreeView,
hDevItem,
dnDevInst,
bShowHidden);
}
while (cr == CR_SUCCESS)
{
@ -564,13 +585,15 @@ EnumChildDevices(HWND hTreeView,
hDevItem = AddDeviceToTree(hTreeView,
hRoot,
dnDevInst);
if (hDevItem == NULL)
break;
EnumChildDevices(hTreeView,
hDevItem,
dnDevInst);
dnDevInst,
bShowHidden);
if (hDevItem != NULL)
{
EnumChildDevices(hTreeView,
hDevItem,
dnDevInst,
bShowHidden);
}
}
(void)TreeView_SortChildren(hTreeView,
@ -581,7 +604,8 @@ EnumChildDevices(HWND hTreeView,
VOID
ListDevicesByConnection(HWND hTreeView,
HTREEITEM hRoot)
HTREEITEM hRoot,
BOOL bShowHidden)
{
DEVINST devInst;
CONFIGRET cr;
@ -592,7 +616,8 @@ ListDevicesByConnection(HWND hTreeView,
if (cr == CR_SUCCESS)
EnumChildDevices(hTreeView,
hRoot,
devInst);
devInst,
bShowHidden);
(void)TreeView_Expand(hTreeView,
hRoot,

View file

@ -20,6 +20,8 @@ BEGIN
MENUITEM "Устройствата според свързването", IDC_DEVBYCONN
MENUITEM "Средствата според вида", IDC_RESBYTYPE, GRAYED
MENUITEM "Средствата според свързването", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Помощ"
BEGIN

View file

@ -20,6 +20,8 @@ BEGIN
MENUITEM "Zařízení podle připojení", IDC_DEVBYCONN
MENUITEM "Prostředky podle typu", IDC_RESBYTYPE, GRAYED
MENUITEM "Prostředky podle připojení", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Nápověda"
BEGIN

View file

@ -1,4 +1,4 @@
LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL
LANGUAGE LANG_GERMAN, SUBLANG_NEUTRAL
IDR_MAINMENU MENU
BEGIN
@ -20,6 +20,8 @@ BEGIN
MENUITEM "Geräte nach Verbindung", IDC_DEVBYCONN
MENUITEM "Resourcen nach Typ", IDC_RESBYTYPE, GRAYED
MENUITEM "Resourcen nach Verbindung", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Ausgeblendete Geräte anzeigen", IDC_SHOWHIDDEN
END
POPUP "&?"
BEGIN

View file

@ -20,6 +20,8 @@ BEGIN
MENUITEM "Συσκευές ανά σύνδεση", IDC_DEVBYCONN
MENUITEM "Πηγές ανά τύπο", IDC_RESBYTYPE, GRAYED
MENUITEM "Πηγές ανά σύνδεση", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Βοήθεια"
BEGIN

View file

@ -20,6 +20,8 @@ BEGIN
MENUITEM "Devices by connection", IDC_DEVBYCONN
MENUITEM "Resources by type", IDC_RESBYTYPE, GRAYED
MENUITEM "Resources by connection", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Help"
BEGIN

View file

@ -25,6 +25,8 @@ BEGIN
MENUITEM "Dispositivos por conexión", IDC_DEVBYCONN
MENUITEM "Recursos por tipo", IDC_RESBYTYPE, GRAYED
MENUITEM "Recursos por conexión", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Ayuda"
BEGIN

View file

@ -20,6 +20,8 @@ BEGIN
MENUITEM "Périphériques par connexion", IDC_DEVBYCONN
MENUITEM "Ressources par type", IDC_RESBYTYPE, GRAYED
MENUITEM "Ressources par connexion", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Aide"
BEGIN

View file

@ -20,6 +20,8 @@ BEGIN
MENUITEM "Device dengan koneksi", IDC_DEVBYCONN
MENUITEM "Resource dengan tipe", IDC_RESBYTYPE, GRAYED
MENUITEM "Resource dengan koneksi", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Bantuan"
BEGIN

View file

@ -20,6 +20,8 @@ BEGIN
MENUITEM "Dispositivi per connessione", IDC_DEVBYCONN
MENUITEM "Risorse per tipo", IDC_RESBYTYPE, GRAYED
MENUITEM "Risorse per connessione", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Aiuto"
BEGIN

View file

@ -20,6 +20,8 @@ BEGIN
MENUITEM "デバイス (接続別)", IDC_DEVBYCONN
MENUITEM "リソ ース (種類別)", IDC_RESBYTYPE, GRAYED
MENUITEM "リソ ース (接続別)", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "ヘルプ"
BEGIN

View file

@ -24,6 +24,8 @@ BEGIN
MENUITEM "Devices by connection", IDC_DEVBYCONN
MENUITEM "Resources by type", IDC_RESBYTYPE, GRAYED
MENUITEM "Resources by connection", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "도움말"
BEGIN

View file

@ -20,6 +20,8 @@ BEGIN
MENUITEM "Enheter etter tilkobling", IDC_DEVBYCONN
MENUITEM "Ressurser etter type", IDC_RESBYTYPE, GRAYED
MENUITEM "Ressurser etter tilkobling", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Hjelp"
BEGIN

View file

@ -27,6 +27,8 @@ BEGIN
MENUITEM "Ur&ządzenia według połączenia", IDC_DEVBYCONN
MENUITEM "Zaso&by według typu", IDC_RESBYTYPE, GRAYED
MENUITEM "Za&soby według połączenia", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Pomo&c"
BEGIN

View file

@ -21,6 +21,8 @@ BEGIN
MENUITEM "Dispozitive după &conexiune", IDC_DEVBYCONN
MENUITEM "Resurse după t&ip", IDC_RESBYTYPE, GRAYED
MENUITEM "Resurse după c&onexiune", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "&?"
BEGIN

View file

@ -22,6 +22,8 @@ BEGIN
MENUITEM "Устройства по подключению", IDC_DEVBYCONN
MENUITEM "Ресурсы по типу", IDC_RESBYTYPE, GRAYED
MENUITEM "Ресурсы по подключению", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Справка"
BEGIN

View file

@ -25,6 +25,8 @@ BEGIN
MENUITEM "Zariadenia podľa pripojenia", IDC_DEVBYCONN
MENUITEM "Prostriedky podľa typu", IDC_RESBYTYPE, GRAYED
MENUITEM "Prostriedky podľa pripojenia", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Pomocník"
BEGIN

View file

@ -27,6 +27,8 @@ BEGIN
MENUITEM "Enheter efter koppling", IDC_DEVBYCONN
MENUITEM "Resurcer efter typ", IDC_RESBYTYPE, GRAYED
MENUITEM "Resurcer efter koppling", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Hjälp"
BEGIN

View file

@ -28,6 +28,8 @@ BEGIN
MENUITEM "อุปกรณ์แบ่งตามการเชื่อมต่อ", IDC_DEVBYCONN
MENUITEM "แหล่งข้อมูลตามประเภท", IDC_RESBYTYPE, GRAYED
MENUITEM "แหล่งข้อมูลตามการเชื่อมต่อ", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "ช่วยเหลือ"
BEGIN

View file

@ -28,6 +28,8 @@ BEGIN
MENUITEM "Пристрої за підключенням", IDC_DEVBYCONN
MENUITEM "Ресурси за типом", IDC_RESBYTYPE, GRAYED
MENUITEM "Ресурси за підключенням", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "Довідка"
BEGIN

View file

@ -24,6 +24,8 @@ BEGIN
MENUITEM "设备,按连接", IDC_DEVBYCONN
MENUITEM "资源,按类型", IDC_RESBYTYPE, GRAYED
MENUITEM "资源,按连接", IDC_RESBYCONN, GRAYED
MENUITEM SEPARATOR
MENUITEM "Show hidden devices", IDC_SHOWHIDDEN
END
POPUP "帮助"
BEGIN

View file

@ -217,11 +217,11 @@ DeviceEnumThread(LPVOID lpParameter)
switch (Info->Display)
{
case DevicesByType:
ListDevicesByType(Info->hTreeView, hRoot);
ListDevicesByType(Info->hTreeView, hRoot, Info->bShowHidden);
break;
case DevicesByConnection:
ListDevicesByConnection(Info->hTreeView, hRoot);
ListDevicesByConnection(Info->hTreeView, hRoot, Info->bShowHidden);
break;
default:
@ -238,6 +238,9 @@ static VOID
UpdateViewMenu(PMAIN_WND_INFO Info)
{
UINT id = IDC_DEVBYTYPE;
HMENU hMenu;
hMenu = GetMenu(Info->hMainWnd);
switch (Info->Display)
{
@ -255,11 +258,15 @@ UpdateViewMenu(PMAIN_WND_INFO Info)
break;
}
CheckMenuRadioItem(GetMenu(Info->hMainWnd),
CheckMenuRadioItem(hMenu,
IDC_DEVBYTYPE,
IDC_RESBYCONN,
id,
MF_BYCOMMAND);
CheckMenuItem(hMenu,
IDC_SHOWHIDDEN,
MF_BYCOMMAND | (Info->bShowHidden) ? MF_CHECKED : MF_UNCHECKED);
}
@ -598,6 +605,14 @@ MainWndCommand(PMAIN_WND_INFO Info,
OnRefresh(Info);
}
break;
case IDC_SHOWHIDDEN:
{
Info->bShowHidden = !Info->bShowHidden;
UpdateViewMenu(Info);
OnRefresh(Info);
}
break;
}
}
@ -794,6 +809,7 @@ CreateMainWindow(LPCTSTR lpCaption,
{
Info->nCmdShow = nCmdShow;
Info->Display = DevicesByType;
Info->bShowHidden = TRUE;
hMainWnd = CreateWindowEx(WS_EX_WINDOWEDGE,
szMainWndClass,

View file

@ -40,6 +40,7 @@ typedef struct _MAIN_WND_INFO
int nCmdShow;
DISPLAY_TYPE Display;
BOOL bShowHidden;
/* status flags */
UINT InMenuLoop : 1;
@ -71,8 +72,8 @@ HWND CreateMainWindow(LPCTSTR lpCaption, int nCmdShow);
VOID FreeDeviceStrings(HWND hTreeView);
VOID OpenPropSheet(HWND hTreeView, HTREEITEM hItem);
HTREEITEM InitTreeView(HWND hTreeView);
VOID ListDevicesByType(HWND hTreeView, HTREEITEM hRoot);
VOID ListDevicesByConnection(HWND hTreeView, HTREEITEM hRoot);
VOID ListDevicesByType(HWND hTreeView, HTREEITEM hRoot, BOOL bShowHidden);
VOID ListDevicesByConnection(HWND hTreeView, HTREEITEM hRoot, BOOL bShowHidden);
/* misc.c */

View file

@ -23,6 +23,7 @@
#define IDC_DEVBYCONN 105
#define IDC_RESBYTYPE 106
#define IDC_RESBYCONN 107
#define IDC_SHOWHIDDEN 108
/* tooltips */
#define IDS_TOOLTIP_PROP 6000