[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
This commit is contained in:
Ged Murphy 2014-11-27 13:47:49 +00:00
parent 267881ff71
commit 7a8c45344a
11 changed files with 230 additions and 134 deletions

View file

@ -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)

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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:
{

View file

@ -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
);
};

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
name="ReactOS.Apps.devmgmt"
processorArchitecture="*"
version="1.0.0.0"
type="win32"/>
<description>ReactOS Device Manager</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>

View file

@ -5,11 +5,6 @@ VisualStudioVersion = 12.0.30501.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "devmgmt_new", "devmgmt_new.vcxproj", "{47B3358F-E7C3-4D02-9310-68813B9292E0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9ED8D860-F1E9-4F32-8EE7-D8BAEC9BF319}"
ProjectSection(SolutionItems) = preProject
Performance1.psess = Performance1.psess
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32

View file

@ -41,9 +41,11 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -56,7 +58,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>comctl32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>UxTheme.lib;comctl32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
<PreprocessorDefinitions>LANGUAGE_EN_US;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -77,7 +79,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>comctl32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>UxTheme.lib;comctl32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>

View file

@ -6,6 +6,7 @@
#include <setupapi.h>
#include <cfgmgr32.h>
#include <commctrl.h>
#include <Uxtheme.h>
#include <Cfgmgr32.h>
#include <devguid.h>