From 7a8c45344a05140cf4657580578362bad248d615 Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Thu, 27 Nov 2014 13:47:49 +0000 Subject: [PATCH] [DEVICE_MANAGER] - Test whether a driver is hidden or not by checking its status instead of the old hack of hiding certain classes which we deemed should be hidden. - Add support for hiding devices and problem overlays when showing by connection. - We now show and hide identical devices when run alongside the Win8 MS device manager in both by type and by connection. - Update the radio buttons when selecting the menu type. - Add a manifest and use Win7 arrows on the TreeView. svn path=/trunk/; revision=65502 --- .../mscutils/devmgmt_new/DeviceView.cpp | 144 ++++++++++++------ .../mscutils/devmgmt_new/DeviceView.h | 14 +- .../mscutils/devmgmt_new/Devices.cpp | 53 +++---- .../mscutils/devmgmt_new/Devices.h | 13 +- .../mscutils/devmgmt_new/MainWindow.cpp | 63 +++++--- .../mscutils/devmgmt_new/MainWindow.h | 41 +++-- .../mscutils/devmgmt_new/devmgmt.exe.manifest | 24 +++ .../mscutils/devmgmt_new/devmgmt.rc | Bin 596 -> 884 bytes .../mscutils/devmgmt_new/devmgmt_new.sln | 5 - .../mscutils/devmgmt_new/devmgmt_new.vcxproj | 6 +- .../mscutils/devmgmt_new/stdafx.h | 1 + 11 files changed, 230 insertions(+), 134 deletions(-) create mode 100644 reactos/base/applications/mscutils/devmgmt_new/devmgmt.exe.manifest diff --git a/reactos/base/applications/mscutils/devmgmt_new/DeviceView.cpp b/reactos/base/applications/mscutils/devmgmt_new/DeviceView.cpp index 0d68c830d76..4999421ff34 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/DeviceView.cpp +++ b/reactos/base/applications/mscutils/devmgmt_new/DeviceView.cpp @@ -35,16 +35,16 @@ typedef INT_PTR(WINAPI *pDevicePropertiesExW)(HWND,LPCWSTR,LPCWSTR,DWORD,BOOL); /* PUBLIC METHODS *************************************/ CDeviceView::CDeviceView( - HWND hMainWnd + HWND hMainWnd, + ListDevices List ) : m_Devices(NULL), m_hMainWnd(hMainWnd), m_hTreeView(NULL), m_hPropertyDialog(NULL), m_hShortcutMenu(NULL), - m_ListDevices(DevicesByType), - m_ShowHidden(FALSE), - m_ShowUnknown(TRUE) + m_ListDevices(List), + m_ShowHidden(FALSE) { m_Devices = new CDevices(); } @@ -85,8 +85,8 @@ CDeviceView::Initialize() m_ImageList, TVSIL_NORMAL); - /* Display the devices */ - Refresh(); + /* Give the treeview arrows instead of +/- boxes (on Win7) */ + SetWindowTheme(m_hTreeView, L"explorer", NULL); } return !!(m_hTreeView); @@ -224,9 +224,6 @@ CDeviceView::ListDevicesByType() INT ClassIndex; INT ClassImage; LPTSTR DeviceId = NULL; - - BOOL IsUnknown = FALSE; - BOOL IsHidden = FALSE; BOOL bSuccess; @@ -255,12 +252,8 @@ CDeviceView::ListDevicesByType() CLASS_NAME_LEN, ClassDescription, CLASS_DESC_LEN, - &ClassImage, - &IsUnknown, - &IsHidden); - if (bSuccess && - (IsUnknown == FALSE || (IsUnknown && m_ShowUnknown)) && - (IsHidden == FALSE || (IsHidden && m_ShowHidden))) + &ClassImage); + if (bSuccess) { BOOL bDevSuccess, AddedParent; HANDLE Handle = NULL; @@ -268,7 +261,8 @@ CDeviceView::ListDevicesByType() INT DeviceIndex = 0; BOOL MoreItems = FALSE; BOOL DeviceHasProblem = FALSE; - ULONG DeviceStatus, ProblemNumber; + ULONG DeviceStatus = 0; + ULONG ProblemNumber = 0; ULONG OverlayImage = 0; AddedParent = FALSE; @@ -282,9 +276,35 @@ CDeviceView::ListDevicesByType() &MoreItems, DeviceName, DEVICE_NAME_LEN, - &DeviceId); + &DeviceId, + &DeviceStatus, + &ProblemNumber); if (bDevSuccess) { + /* Check if this is a hidden device */ + if (DeviceStatus & DN_NO_SHOW_IN_DM) + { + if (m_ShowHidden == FALSE) + { + DeviceIndex++; + continue; + } + } + + /* Check if the device has a problem */ + if (DeviceStatus & DN_HAS_PROBLEM) + { + DeviceHasProblem = TRUE; + OverlayImage = 1; + } + + /* The disabled overlay takes precidence over the problem overlay */ + if (ProblemNumber == CM_PROB_HARDWARE_DISABLED) + { + OverlayImage = 2; + } + + /* We have a device, we're gonna need to add the parent first */ if (AddedParent == FALSE) { @@ -299,26 +319,6 @@ CDeviceView::ListDevicesByType() AddedParent = TRUE; } - /* Get the status of the device */ - if (m_Devices->GetDeviceStatus(DeviceId, - &DeviceStatus, - &ProblemNumber)) - { - /* Check if the device has a problem */ - if (DeviceStatus & DN_HAS_PROBLEM) - { - DeviceHasProblem = TRUE; - OverlayImage = 1; - } - - /* The disabled overlay takes precidence over the problem overlay */ - if (ProblemNumber == CM_PROB_DISABLED || - ProblemNumber == CM_PROB_HARDWARE_DISABLED) - { - OverlayImage = 2; - } - } - /* Add the device under the class item */ (VOID)InsertIntoTreeView(hDevItem, DeviceName, @@ -414,6 +414,9 @@ CDeviceView::RecurseChildDevices( INT ClassImage; BOOL IsUnknown = FALSE; BOOL IsHidden = FALSE; + ULONG DeviceStatus = 0; + ULONG ProblemNumber = 0; + UINT OverlayImage = 0; BOOL bSuccess; /* Check if the parent has any child devices */ @@ -426,20 +429,38 @@ CDeviceView::RecurseChildDevices( DEVICE_NAME_LEN, &DeviceId, &ClassImage, - &IsUnknown, - &IsHidden); + &DeviceStatus, + &ProblemNumber); if (bSuccess) { - /* Add this device to the tree under its parent */ - hDevItem = InsertIntoTreeView(hParentTreeItem, - DeviceName, - (LPARAM)DeviceId, - ClassImage, - 0); - if (hDevItem) + /* Check if this is a hidden device */ + if ((m_ShowHidden == TRUE) || (!(DeviceStatus & DN_NO_SHOW_IN_DM))) { - /* Check if this child has any children itself */ - RecurseChildDevices(Device, hDevItem); + /* Check if the device has a problem */ + if (DeviceStatus & DN_HAS_PROBLEM) + { + OverlayImage = 1; + } + + /* The disabled overlay takes precidence over the problem overlay */ + if (ProblemNumber == CM_PROB_HARDWARE_DISABLED) + { + OverlayImage = 2; + } + + /* Add this device to the tree under its parent */ + hDevItem = InsertIntoTreeView(hParentTreeItem, + DeviceName, + (LPARAM)DeviceId, + ClassImage, + 0); + + + if (hDevItem) + { + /* Check if this child has any children itself */ + RecurseChildDevices(Device, hDevItem); + } } } @@ -456,10 +477,30 @@ CDeviceView::RecurseChildDevices( DEVICE_NAME_LEN, &DeviceId, &ClassImage, - &IsUnknown, - &IsHidden); + &DeviceStatus, + &ProblemNumber); if (bSuccess) { + /* Check if this is a hidden device */ + if (DeviceStatus & DN_NO_SHOW_IN_DM) + { + if (m_ShowHidden == FALSE) + continue; + } + + /* Check if the device has a problem */ + if (DeviceStatus & DN_HAS_PROBLEM) + { + OverlayImage = 1; + } + + /* The disabled overlay takes precidence over the problem overlay */ + if (ProblemNumber == CM_PROB_HARDWARE_DISABLED) + { + OverlayImage = 2; + } + + /* Add this device to the tree under its parent */ hDevItem = InsertIntoTreeView(hParentTreeItem, DeviceName, @@ -530,6 +571,7 @@ CDeviceView::RecurseDeviceView( tvItem.hItem = hItem; tvItem.mask = TVIF_PARAM; + /* Get the item data */ if (TreeView_GetItem(m_hTreeView, &tvItem) && tvItem.lParam != NULL) { @@ -546,9 +588,11 @@ CDeviceView::RecurseDeviceView( hItem = TreeView_GetNextSibling(m_hTreeView, hItem); if (hItem == NULL) break; + /* The lParam contains the device id */ tvItem.hItem = hItem; tvItem.mask = TVIF_PARAM; + /* Get the item data and free the device id */ if (TreeView_GetItem(m_hTreeView, &tvItem)) { if (tvItem.lParam != NULL) diff --git a/reactos/base/applications/mscutils/devmgmt_new/DeviceView.h b/reactos/base/applications/mscutils/devmgmt_new/DeviceView.h index c2e3ea2a5a5..8466bca512b 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/DeviceView.h +++ b/reactos/base/applications/mscutils/devmgmt_new/DeviceView.h @@ -19,15 +19,16 @@ class CDeviceView : public CDevices ListDevices m_ListDevices; HIMAGELIST m_ImageList; - //HDEVINFO m_hDevInfo; - HTREEITEM m_hTreeRoot; BOOL m_ShowHidden; - BOOL m_ShowUnknown; public: - CDeviceView(HWND hMainWnd); + CDeviceView( + HWND hMainWnd, + ListDevices List + ); + ~CDeviceView(void); BOOL Initialize(); @@ -54,11 +55,6 @@ public: m_ShowHidden = ShowHidden; } - VOID ShowUnknownDevices(BOOL ShowUnknown) - { - m_ShowUnknown = ShowUnknown; - } - private: static unsigned int __stdcall ListDevicesThread( void *Param diff --git a/reactos/base/applications/mscutils/devmgmt_new/Devices.cpp b/reactos/base/applications/mscutils/devmgmt_new/Devices.cpp index 42f2cf99c95..526beb3f416 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/Devices.cpp +++ b/reactos/base/applications/mscutils/devmgmt_new/Devices.cpp @@ -138,14 +138,15 @@ CDevices::GetDevice( _In_ DWORD DeviceNameSize, _Outptr_ LPWSTR *DeviceId, _Out_ PINT ClassImage, - _Out_ LPBOOL IsUnknown, - _Out_ LPBOOL IsHidden + _Out_ PULONG Status, + _Out_ PULONG ProblemNumber ) { WCHAR ClassGuidString[MAX_GUID_STRING_LEN]; GUID ClassGuid; ULONG ulLength; CONFIGRET cr; + BOOL bSuccess; *DeviceId = NULL; @@ -153,11 +154,13 @@ CDevices::GetDevice( cr = CM_Get_Device_ID_Size(&ulLength, Device, 0); if (cr == CR_SUCCESS) { + /* We alloc heap here because this will be stored in the lParam of the TV */ *DeviceId = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (ulLength + 1) * sizeof(WCHAR)); if (*DeviceId) { + /* Now get the actual device id */ cr = CM_Get_Device_IDW(Device, *DeviceId, ulLength + 1, @@ -175,6 +178,15 @@ CDevices::GetDevice( return FALSE; + /* Get the current status of the device */ + bSuccess = GetDeviceStatus(*DeviceId, Status, ProblemNumber); + if (bSuccess == FALSE) + { + HeapFree(GetProcessHeap(), 0, *DeviceId); + *DeviceId = NULL; + return FALSE; + } + /* Get the class guid for this device */ ulLength = MAX_GUID_STRING_LEN * sizeof(WCHAR); cr = CM_Get_DevNode_Registry_PropertyW(Device, @@ -187,21 +199,14 @@ CDevices::GetDevice( { /* Convert the string to a proper guid */ CLSIDFromString(ClassGuidString, &ClassGuid); - - /* Check if this is a hidden device */ - if ((IsEqualGUID(ClassGuid, GUID_DEVCLASS_LEGACYDRIVER) || - IsEqualGUID(ClassGuid, GUID_DEVCLASS_VOLUME))) - { - *IsHidden = TRUE; - } } else { /* It's a device with no driver */ ClassGuid = GUID_DEVCLASS_UNKNOWN; - *IsUnknown = TRUE; } + /* Get the image for the class this device is in */ SetupDiGetClassImageIndex(&m_ImageListData, &ClassGuid, @@ -245,9 +250,7 @@ CDevices::EnumClasses( _In_ DWORD ClassNameSize, _Out_writes_(ClassDescSize) LPWSTR ClassDesc, _In_ DWORD ClassDescSize, - _Out_ PINT ClassImage, - _Out_ LPBOOL IsUnknown, - _Out_ LPBOOL IsHidden + _Out_ PINT ClassImage ) { DWORD RequiredSize, Type, Size; @@ -258,8 +261,6 @@ CDevices::EnumClasses( ClassName[0] = UNICODE_NULL; ClassDesc[0] = UNICODE_NULL; *ClassImage = -1; - *IsUnknown = FALSE; - *IsHidden = FALSE; /* Get the next class in the list */ cr = CM_Enumerate_Classes(ClassIndex, @@ -332,16 +333,6 @@ CDevices::EnumClasses( ClassGuid, ClassImage); - /* Check if this is an unknown device */ - *IsUnknown = IsEqualGUID(*ClassGuid, GUID_DEVCLASS_UNKNOWN); - - /* Check if this is one of the classes we hide by default */ - if (IsEqualGUID(*ClassGuid, GUID_DEVCLASS_LEGACYDRIVER) || - IsEqualGUID(*ClassGuid, GUID_DEVCLASS_VOLUME)) - { - *IsHidden = TRUE; - } - return TRUE; } @@ -353,7 +344,9 @@ CDevices::EnumDevicesForClass( _Out_ LPBOOL MoreItems, _Out_ LPTSTR DeviceName, _In_ DWORD DeviceNameSize, - _Outptr_ LPTSTR *DeviceId + _Outptr_ LPTSTR *DeviceId, + _Out_ PULONG Status, + _Out_ PULONG ProblemNumber ) { SP_DEVINFO_DATA DeviceInfoData; @@ -454,7 +447,6 @@ CDevices::EnumDevicesForClass( NULL); if (bSuccess == FALSE) goto Quit; - /* Skip the root device */ if (*DeviceId != NULL && wcscmp(*DeviceId, L"HTREE\\ROOT\\0") == 0) @@ -463,6 +455,12 @@ CDevices::EnumDevicesForClass( goto Quit; } + + /* Get the current status of the device */ + bSuccess = GetDeviceStatus(*DeviceId, Status, ProblemNumber); + if (bSuccess == FALSE) goto Quit; + + /* Get the device's friendly name */ bSuccess = SetupDiGetDeviceRegistryPropertyW(hDevInfo, &DeviceInfoData, @@ -552,7 +550,6 @@ Cleanup: return bSuccess; } - DWORD CDevices::ConvertResourceDescriptorToString( _Inout_z_ LPWSTR ResourceDescriptor, diff --git a/reactos/base/applications/mscutils/devmgmt_new/Devices.h b/reactos/base/applications/mscutils/devmgmt_new/Devices.h index 7a7dc64574a..5b2ee81a1a3 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/Devices.h +++ b/reactos/base/applications/mscutils/devmgmt_new/Devices.h @@ -44,8 +44,8 @@ public: _In_ DWORD DeviceNameSize, _Outptr_ LPTSTR *DeviceId, _Out_ PINT ClassImage, - _Out_ LPBOOL IsUnknown, - _Out_ LPBOOL IsHidden + _Out_ PULONG Status, + _Out_ PULONG ProblemNumber ); BOOL EnumClasses( @@ -55,9 +55,7 @@ public: _In_ DWORD ClassNameSize, _Out_writes_(ClassDescSize) LPWSTR ClassDesc, _In_ DWORD ClassDescSize, - _Out_ PINT ClassImage, - _Out_ LPBOOL IsUnknown, - _Out_ LPBOOL IsHidden + _Out_ PINT ClassImage ); BOOL EnumDevicesForClass( @@ -67,7 +65,9 @@ public: _Out_ LPBOOL MoreItems, _Out_writes_(DeviceNameSize) LPTSTR DeviceName, _In_ DWORD DeviceNameSize, - _Outptr_ LPTSTR *DeviceId + _Outptr_ LPTSTR *DeviceId, + _Out_ PULONG Status, + _Out_ PULONG ProblemNumber ); BOOL GetDeviceStatus( @@ -87,7 +87,6 @@ private: BOOL CreateRootDevice( ); - DWORD ConvertResourceDescriptorToString( _Inout_z_ LPWSTR ResourceDescriptor, _In_ DWORD ResourceDescriptorSize diff --git a/reactos/base/applications/mscutils/devmgmt_new/MainWindow.cpp b/reactos/base/applications/mscutils/devmgmt_new/MainWindow.cpp index 3dbfc0a5c41..95a996d43ad 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/MainWindow.cpp +++ b/reactos/base/applications/mscutils/devmgmt_new/MainWindow.cpp @@ -105,10 +105,6 @@ CMainWindow::Initialize(LPCTSTR lpCaption, NULL, g_hInstance, this); - if (m_hMainWnd) - { - m_hMenu = GetMenu(m_hMainWnd); - } } /* Return creation result */ @@ -171,6 +167,38 @@ CMainWindow::MainWndMenuHint(WORD CmdId, return Found; } +BOOL +CMainWindow::UpdateDevicesDisplay(ListDevices List) +{ + UINT CheckId; + BOOL bSuccess; + + /* Set the new type*/ + m_DeviceView->SetDeviceListType(List); + + /* Get the menu item id */ + switch (List) + { + case DevicesByType: CheckId = IDC_DEVBYTYPE; break; + case DevicesByConnection: CheckId = IDC_DEVBYCONN; break; + case ResourcesByType: CheckId = IDC_RESBYTYPE; break; + case ResourcesByConnection: CheckId = IDC_RESBYCONN; break; + default: ATLASSERT(FALSE); break; + } + + /* Set the new check item */ + bSuccess = CheckMenuRadioItem(m_hMenu, + IDC_DEVBYTYPE, + IDC_RESBYCONN, + CheckId, + MF_BYCOMMAND); + + /* Refresh the view */ + m_DeviceView->Refresh(); + + return TRUE; +} + BOOL CMainWindow::CreateToolBar() { @@ -329,15 +357,20 @@ CMainWindow::OnCreate(HWND hwnd) /* Store the window handle */ m_hMainWnd = hwnd; + /* Get the menu handle */ + m_hMenu = GetMenu(m_hMainWnd); + /* Create the toolbar */ if (CreateToolBar() && CreateStatusBar()) { /* Create the device view object */ - m_DeviceView = new CDeviceView(m_hMainWnd); + m_DeviceView = new CDeviceView(m_hMainWnd, DevicesByType); /* Initialize it */ if (m_DeviceView->Initialize()) { + UpdateDevicesDisplay(DevicesByType); + /* Display the window according to the user request */ ShowWindow(hwnd, m_CmdShow); @@ -450,27 +483,15 @@ CMainWindow::OnCommand(WPARAM wParam, case IDC_DEVBYTYPE: { - m_DeviceView->SetDeviceListType(DevicesByType); - CheckMenuRadioItem(m_hMenu, - IDC_DEVBYTYPE, - IDC_RESBYCONN, - IDC_DEVBYTYPE, - MF_BYCOMMAND); - m_DeviceView->Refresh(); + UpdateDevicesDisplay(DevicesByType); + break; } - break; case IDC_DEVBYCONN: { - m_DeviceView->SetDeviceListType(DevicesByConnection); - CheckMenuRadioItem(m_hMenu, - IDC_DEVBYTYPE, - IDC_RESBYCONN, - IDC_DEVBYCONN, - MF_BYCOMMAND); - m_DeviceView->Refresh(); + UpdateDevicesDisplay(DevicesByConnection); + break; } - break; case IDC_SHOWHIDDEN: { diff --git a/reactos/base/applications/mscutils/devmgmt_new/MainWindow.h b/reactos/base/applications/mscutils/devmgmt_new/MainWindow.h index a9bf229a767..0ac89e2afa6 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/MainWindow.h +++ b/reactos/base/applications/mscutils/devmgmt_new/MainWindow.h @@ -18,8 +18,21 @@ class CMainWindow HMENU m_hMenu; int m_CmdShow; +public: + CMainWindow(void); + ~CMainWindow(void); + + BOOL Initialize(LPCTSTR lpCaption, int nCmdShow); + INT Run(); + VOID Uninitialize(); + private: - static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + static LRESULT CALLBACK MainWndProc( + HWND hwnd, + UINT msg, + WPARAM wParam, + LPARAM lParam + ); LRESULT OnCreate(HWND hwnd); LRESULT OnDestroy(); @@ -30,19 +43,23 @@ private: BOOL CreateToolBar(); BOOL CreateStatusBar(); - BOOL StatusBarLoadString(HWND hStatusBar, INT PartId, HINSTANCE hInstance, UINT uID); - BOOL MainWndMenuHint(WORD CmdId, - const MENU_HINT *HintArray, - DWORD HintsCount, - UINT DefHintId); -public: - CMainWindow(void); - ~CMainWindow(void); + BOOL StatusBarLoadString( + HWND hStatusBar, + INT PartId, + HINSTANCE hInstance, + UINT uID + ); - BOOL Initialize(LPCTSTR lpCaption, int nCmdShow); - INT Run(); - VOID Uninitialize(); + BOOL MainWndMenuHint( + WORD CmdId, + const MENU_HINT *HintArray, + DWORD HintsCount, + UINT DefHintId + ); + BOOL UpdateDevicesDisplay( + ListDevices List + ); }; diff --git a/reactos/base/applications/mscutils/devmgmt_new/devmgmt.exe.manifest b/reactos/base/applications/mscutils/devmgmt_new/devmgmt.exe.manifest new file mode 100644 index 00000000000..0c2924a0984 --- /dev/null +++ b/reactos/base/applications/mscutils/devmgmt_new/devmgmt.exe.manifest @@ -0,0 +1,24 @@ + + + +ReactOS Device Manager + + + + + + + diff --git a/reactos/base/applications/mscutils/devmgmt_new/devmgmt.rc b/reactos/base/applications/mscutils/devmgmt_new/devmgmt.rc index ec5d1382349daa3b346da89ade1e4e297e4385ab..e38c107f190c3a8e39f722296e895d03c4899c36 100644 GIT binary patch delta 251 zcmcb@@`Y`~Ge&J*1}+9=hD?Suh7^WWAgRC*4}?Jst_+S0&I}<8{tUrj5um!sFB$D8 zzhYFW&t*tt$OG$1WhiDS0m`Q`Q~ U;LgYcdJX8o$;wQIEFh-=05I|^ true + false false + false @@ -56,7 +58,7 @@ Windows true - comctl32.lib;setupapi.lib;%(AdditionalDependencies) + UxTheme.lib;comctl32.lib;setupapi.lib;%(AdditionalDependencies) LANGUAGE_EN_US;%(PreprocessorDefinitions) @@ -77,7 +79,7 @@ true true true - comctl32.lib;setupapi.lib;%(AdditionalDependencies) + UxTheme.lib;comctl32.lib;setupapi.lib;%(AdditionalDependencies) diff --git a/reactos/base/applications/mscutils/devmgmt_new/stdafx.h b/reactos/base/applications/mscutils/devmgmt_new/stdafx.h index fdbebc24fd9..c7c9cac75cb 100644 --- a/reactos/base/applications/mscutils/devmgmt_new/stdafx.h +++ b/reactos/base/applications/mscutils/devmgmt_new/stdafx.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include