ReactOS 0.4.16-dev-1946-g52006dd
CDeviceView Class Reference

#include <DeviceView.h>

Collaboration diagram for CDeviceView:

Public Member Functions

 CDeviceView (HWND hMainWnd)
 
 ~CDeviceView (void)
 
bool Initialize ()
 
bool Uninitialize ()
 
LRESULT OnSize (_In_ int x, _In_ int y, _In_ int cx, _In_ int cy)
 
LRESULT OnDoubleClick (_In_ LPNMHDR NmHdr)
 
LRESULT OnRightClick (_In_ LPNMHDR NmHdr)
 
LRESULT OnContextMenu (_In_ LPARAM lParam)
 
LRESULT OnAction (UINT Action)
 
VOID Refresh (_In_ ViewType Type, _In_ bool ScanForChanges, _In_ bool UpdateView)
 
VOID DisplayPropertySheet ()
 
VOID SetFocus ()
 
VOID SetHiddenDevices (_In_ bool ShowHidden)
 
ViewType GetCurrentView ()
 
bool CreateActionMenu (_In_ HMENU OwnerMenu, _In_ bool MainMenu)
 
CNodeGetSelectedNode ()
 
bool SelDeviceIsStarted ()
 
bool SelDeviceIsInstalled ()
 

Private Member Functions

bool AddRootDevice ()
 
bool RefreshDeviceList ()
 
bool ListDevicesByConnection ()
 
bool ListDevicesByType ()
 
bool ListResourcesByType ()
 
bool RecurseResources (_In_ DEVINST ParentDevice, _In_ HTREEITEM hMemoryTreeItem, _In_ HTREEITEM hPortTreeItem, _In_ HTREEITEM hDmaTreeItem, _In_ HTREEITEM hIrqTreeItem)
 
bool GetNextClass (_In_ ULONG ClassIndex, _Out_ LPGUID ClassGuid, _Out_ HDEVINFO *hDevInfo)
 
bool RecurseChildDevices (_In_ DEVINST ParentDevice, _In_ HTREEITEM hParentTreeItem)
 
bool EnableSelectedDevice (_In_ bool Enable, _Out_ bool &NeedsReboot)
 
bool UpdateSelectedDevice (_Out_ bool &NeedsReboot)
 
bool UninstallSelectedDevice ()
 
bool RunAddHardwareWizard ()
 
bool GetChildDevice (_In_ DEVINST ParentDevInst, _Out_ PDEVINST DevInst)
 
bool GetSiblingDevice (_In_ DEVINST PrevDevice, _Out_ PDEVINST DevInst)
 
HTREEITEM InsertIntoTreeView (_In_opt_ HTREEITEM hParent, _In_ CNode *Node)
 
void BuildActionMenuForNode (_In_ HMENU OwnerMenu, _In_ CNode *Node, _In_ bool MainMenu)
 
HTREEITEM RecurseFindDevice (_In_ HTREEITEM hParentItem, _In_ CNode *Node)
 
void SelectNode (_In_ CNode *Node)
 
void EmptyDeviceView ()
 
CNodeGetNode (_In_ LPTV_ITEMW TvItem)
 
CClassNodeGetClassNode (_In_ LPGUID ClassGuid)
 
CDeviceNodeGetDeviceNode (_In_ DEVINST Device)
 
void EmptyLists ()
 

Static Private Member Functions

static unsigned int __stdcall RefreshThread (void *Param)
 

Private Attributes

HWND m_hMainWnd
 
HWND m_hTreeView
 
HWND m_hPropertyDialog
 
HMENU m_hMenu
 
ViewType m_ViewType
 
HTREEITEM m_hTreeRoot
 
bool m_ShowHidden
 
CRootNodem_RootNode
 
CAtlList< CClassNode * > m_ClassNodeList
 
CAtlList< CDeviceNode * > m_DeviceNodeList
 
SP_CLASSIMAGELIST_DATA m_ImageListData
 

Detailed Description

Definition at line 17 of file DeviceView.h.

Constructor & Destructor Documentation

◆ CDeviceView()

CDeviceView::CDeviceView ( HWND  hMainWnd)

Definition at line 35 of file DeviceView.cpp.

37 :
43 m_ShowHidden(false),
45{
47}
@ DevicesByType
Definition: DeviceView.h:10
HWND m_hMainWnd
Definition: DeviceView.h:20
HWND m_hTreeView
Definition: DeviceView.h:21
HMENU m_hMenu
Definition: DeviceView.h:23
HWND m_hPropertyDialog
Definition: DeviceView.h:22
CRootNode * m_RootNode
Definition: DeviceView.h:28
ViewType m_ViewType
Definition: DeviceView.h:24
SP_CLASSIMAGELIST_DATA m_ImageListData
Definition: DeviceView.h:31
bool m_ShowHidden
Definition: DeviceView.h:26
#define NULL
Definition: types.h:112
HWND hMainWnd
Definition: magnifier.c:32
#define ZeroMemory
Definition: minwinbase.h:31

◆ ~CDeviceView()

CDeviceView::~CDeviceView ( void  )

Definition at line 49 of file DeviceView.cpp.

50{
51}

Member Function Documentation

◆ AddRootDevice()

bool CDeviceView::AddRootDevice ( )
private

Definition at line 353 of file DeviceView.cpp.

354{
356 return (m_hTreeRoot != NULL);
357}
HTREEITEM m_hTreeRoot
Definition: DeviceView.h:25
HTREEITEM InsertIntoTreeView(_In_opt_ HTREEITEM hParent, _In_ CNode *Node)
Definition: DeviceView.cpp:981

◆ BuildActionMenuForNode()

void CDeviceView::BuildActionMenuForNode ( _In_ HMENU  OwnerMenu,
_In_ CNode Node,
_In_ bool  MainMenu 
)
private

Definition at line 1017 of file DeviceView.cpp.

1022{
1023 // Create a separator structure
1024 MENUITEMINFOW MenuSeparator = { 0 };
1025 MenuSeparator.cbSize = sizeof(MENUITEMINFOW);
1026 MenuSeparator.fType = MFT_SEPARATOR;
1027
1028 // Setup the
1029 MENUITEMINFOW MenuItemInfo = { 0 };
1030 MenuItemInfo.cbSize = sizeof(MENUITEMINFOW);
1031 MenuItemInfo.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA | MIIM_SUBMENU;
1032 MenuItemInfo.fType = MFT_STRING;
1033
1035 int i = 0;
1036
1037 // Device nodes have extra data
1038 if (Node->GetNodeType() == DeviceNode)
1039 {
1040 CDeviceNode *DeviceNode = dynamic_cast<CDeviceNode *>(Node);
1041
1042 if (DeviceNode->CanUpdate())
1043 {
1045 MenuItemInfo.wID = IDM_UPDATE_DRV;
1046 MenuItemInfo.dwTypeData = String.GetBuffer();
1047 InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
1048 i++;
1049 }
1050
1051 if (DeviceNode->IsDisabled())
1052 {
1054 MenuItemInfo.wID = IDM_ENABLE_DRV;
1055 MenuItemInfo.dwTypeData = String.GetBuffer();
1056 InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
1057 i++;
1058 }
1059
1060 if (DeviceNode->CanDisable() && !DeviceNode->IsDisabled())
1061 {
1063 MenuItemInfo.wID = IDM_DISABLE_DRV;
1064 MenuItemInfo.dwTypeData = String.GetBuffer();
1065 InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
1066 i++;
1067 }
1068
1069 if (DeviceNode->CanUninstall())
1070 {
1072 MenuItemInfo.wID = IDM_UNINSTALL_DRV;
1073 MenuItemInfo.dwTypeData = String.GetBuffer();
1074 InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
1075 i++;
1076 }
1077
1078 InsertMenuItemW(OwnerMenu, i, TRUE, &MenuSeparator);
1079 i++;
1080 }
1081
1082 // All nodes have the scan option
1083 String.LoadStringW(g_hThisInstance, IDS_MENU_SCAN);
1084 MenuItemInfo.wID = IDM_SCAN_HARDWARE;
1085 MenuItemInfo.dwTypeData = String.GetBuffer();
1086 InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
1087 i++;
1088
1089 if ((Node->GetNodeType() == RootNode) || (MainMenu == true))
1090 {
1091 String.LoadStringW(g_hThisInstance, IDS_MENU_ADD);
1092 MenuItemInfo.wID = IDM_ADD_HARDWARE;
1093 MenuItemInfo.dwTypeData = String.GetBuffer();
1094 InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
1095 i++;
1096 }
1097
1098 if (Node->HasProperties())
1099 {
1100 InsertMenuItemW(OwnerMenu, i, TRUE, &MenuSeparator);
1101 i++;
1102
1104 MenuItemInfo.wID = IDM_PROPERTIES;
1105 MenuItemInfo.dwTypeData = String.GetBuffer();
1106 InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
1107 i++;
1108
1110 }
1111}
@ DeviceNode
Definition: Node.h:9
#define IDM_PROPERTIES
Definition: resources.h:9
HINSTANCE g_hThisInstance
Definition: MainWindow.cpp:25
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
union node Node
Definition: types.h:1255
#define IDC_PROPERTIES
Definition: resource.h:32
#define IDS_MENU_SCAN
Definition: resource.h:61
#define IDM_UPDATE_DRV
Definition: resource.h:26
#define IDM_SCAN_HARDWARE
Definition: resource.h:23
#define IDS_MENU_DISABLE
Definition: resource.h:59
#define IDS_MENU_PROPERTIES
Definition: resource.h:63
#define IDM_UNINSTALL_DRV
Definition: resource.h:27
#define IDS_MENU_UNINSTALL
Definition: resource.h:60
#define IDM_ENABLE_DRV
Definition: resource.h:24
#define IDS_MENU_UPDATE
Definition: resource.h:57
#define IDM_DISABLE_DRV
Definition: resource.h:25
#define IDS_MENU_ENABLE
Definition: resource.h:58
#define IDS_MENU_ADD
Definition: resource.h:62
#define IDM_ADD_HARDWARE
Definition: resource.h:28
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PCONFIGURATION_COMPONENT_DATA RootNode
Definition: macharm.c:19
CStringT< wchar_t, StrTraitATL< wchar_t, ChTraitsCRT< wchar_t > > > CAtlStringW
Definition: atlstr.h:126
LPWSTR dwTypeData
Definition: winuser.h:3371
Definition: dlist.c:348
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439
#define MIIM_STRING
Definition: winuser.h:738
#define MIIM_ID
Definition: winuser.h:733
BOOL WINAPI SetMenuDefaultItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define MFT_SEPARATOR
Definition: winuser.h:755
#define MIIM_SUBMENU
Definition: winuser.h:734
#define MFT_STRING
Definition: winuser.h:757
#define MIIM_DATA
Definition: winuser.h:737
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
struct tagMENUITEMINFOW MENUITEMINFOW

Referenced by CreateActionMenu(), and OnContextMenu().

◆ CreateActionMenu()

bool CDeviceView::CreateActionMenu ( _In_ HMENU  OwnerMenu,
_In_ bool  MainMenu 
)

Definition at line 325 of file DeviceView.cpp.

329{
331 if (Node)
332 {
333 BuildActionMenuForNode(OwnerMenu, Node, MainMenu);
334 return true;
335 }
336
337 return false;
338}
void BuildActionMenuForNode(_In_ HMENU OwnerMenu, _In_ CNode *Node, _In_ bool MainMenu)
CNode * GetSelectedNode()
Definition: DeviceView.cpp:341
Definition: Node.h:15

Referenced by CDeviceManager::OnCommand(), and CDeviceManager::OnNotify().

◆ DisplayPropertySheet()

void CDeviceView::DisplayPropertySheet ( )

Definition at line 305 of file DeviceView.cpp.

306{
308 if (Node && Node->HasProperties())
309 {
311 NULL,
312 Node->GetDeviceId(),
313 1,//DPF_EXTENDED,
314 FALSE);
315 }
316}
INT_PTR WINAPI DevicePropertiesExW(IN HWND hWndParent OPTIONAL, IN LPCWSTR lpMachineName OPTIONAL, IN LPCWSTR lpDeviceID OPTIONAL, IN DWORD dwFlags OPTIONAL, IN BOOL bShowDevMgr)
Definition: api.cpp:272

Referenced by OnAction(), OnDoubleClick(), and CDeviceManager::OnNotify().

◆ EmptyDeviceView()

void CDeviceView::EmptyDeviceView ( )
private

Definition at line 1223 of file DeviceView.cpp.

1224{
1226}
#define VOID
Definition: acefi.h:82
#define TreeView_DeleteAllItems(hwnd)
Definition: commctrl.h:3422

Referenced by Uninitialize().

◆ EmptyLists()

void CDeviceView::EmptyLists ( )
private

Definition at line 1298 of file DeviceView.cpp.

1299{
1300 CNode *Node;
1301
1302 while (!m_ClassNodeList.IsEmpty())
1303 {
1304 Node = m_ClassNodeList.RemoveTail();
1305 delete Node;
1306 }
1307
1308 while (!m_DeviceNodeList.IsEmpty())
1309 {
1310 Node = m_DeviceNodeList.RemoveTail();
1311 delete Node;
1312 }
1313}
CAtlList< CClassNode * > m_ClassNodeList
Definition: DeviceView.h:29
CAtlList< CDeviceNode * > m_DeviceNodeList
Definition: DeviceView.h:30

Referenced by RefreshDeviceList().

◆ EnableSelectedDevice()

bool CDeviceView::EnableSelectedDevice ( _In_ bool  Enable,
_Out_ bool NeedsReboot 
)
private

Definition at line 861 of file DeviceView.cpp.

865{
866 CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
867 if (Node == nullptr)
868 return false;
869
870 if (Enable == false)
871 {
873 if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_DISABLE))
874 {
876 str,
877 Node->GetDisplayName(),
879 {
880 return false;
881 }
882 }
883 }
884
885 return Node->EnableDevice(Enable, NeedsReboot);
886}
#define IDS_CONFIRM_DISABLE
Definition: resource.h:53
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
const WCHAR * str
#define MB_YESNO
Definition: winuser.h:828
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONWARNING
Definition: winuser.h:797
#define MB_DEFBUTTON2
Definition: winuser.h:810
#define IDYES
Definition: winuser.h:846

Referenced by OnAction().

◆ GetChildDevice()

bool CDeviceView::GetChildDevice ( _In_ DEVINST  ParentDevInst,
_Out_ PDEVINST  DevInst 
)
private

Definition at line 955 of file DeviceView.cpp.

959{
960 CONFIGRET cr;
961 cr = CM_Get_Child(DevInst,
962 ParentDevInst,
963 0);
964 return (cr == CR_SUCCESS);
965}
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74
#define CR_SUCCESS
Definition: cfgmgr32.h:842
CONFIGRET WINAPI CM_Get_Child(_Out_ PDEVINST pdnDevInst, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags)
Definition: cfgmgr.c:2623

Referenced by RecurseChildDevices(), and RecurseResources().

◆ GetClassNode()

CClassNode * CDeviceView::GetClassNode ( _In_ LPGUID  ClassGuid)
private

Definition at line 1230 of file DeviceView.cpp.

1233{
1234 POSITION Pos;
1235 CClassNode *Node = nullptr;
1236
1237 Pos = m_ClassNodeList.GetHeadPosition();
1238 if (Pos == NULL)
1239 return nullptr;
1240
1241 do
1242 {
1243 Node = m_ClassNodeList.GetNext(Pos);
1244 if (IsEqualGUID(*Node->GetClassGuid(), *ClassGuid))
1245 {
1246 ATLASSERT(Node->GetNodeType() == ClassNode);
1247 break;
1248 }
1249
1250 Node = nullptr;
1251
1252 } while (Pos != NULL);
1253
1254 return Node;
1255}
#define ATLASSERT(x)
Definition: CComVariant.cpp:10
@ ClassNode
Definition: Node.h:8
ush Pos
Definition: deflate.h:92
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147

Referenced by ListDevicesByType().

◆ GetCurrentView()

ViewType CDeviceView::GetCurrentView ( )
inline

Definition at line 80 of file DeviceView.h.

80{ return m_ViewType; }

Referenced by OnAction(), CDeviceManager::OnCommand(), and CDeviceManager::OnCreate().

◆ GetDeviceNode()

CDeviceNode * CDeviceView::GetDeviceNode ( _In_ DEVINST  Device)
private

Definition at line 1258 of file DeviceView.cpp.

1261{
1262 POSITION Pos;
1263 CDeviceNode *Node = nullptr;
1264
1265 Pos = m_DeviceNodeList.GetHeadPosition();
1266 if (Pos == NULL)
1267 return nullptr;
1268
1269 do
1270 {
1271 Node = m_DeviceNodeList.GetNext(Pos);
1272 if (Node->GetDeviceInst() == Device)
1273 {
1274 ATLASSERT(Node->GetNodeType() == DeviceNode);
1275 break;
1276 }
1277
1278 Node = nullptr;
1279
1280 } while (Pos != NULL);
1281
1282 return Node;
1283}
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474

Referenced by ListDevicesByType(), RecurseChildDevices(), and RecurseResources().

◆ GetNextClass()

bool CDeviceView::GetNextClass ( _In_ ULONG  ClassIndex,
_Out_ LPGUID  ClassGuid,
_Out_ HDEVINFO hDevInfo 
)
private

Definition at line 360 of file DeviceView.cpp.

365{
366 CONFIGRET cr;
367
368 // Get the next class in the list
369 cr = CM_Enumerate_Classes(ClassIndex,
370 ClassGuid,
371 0);
372 if (cr != CR_SUCCESS)
373 return false;
374
375 // We only want the devices for this class
376 *hDevInfo = SetupDiGetClassDevsW(ClassGuid,
377 NULL,
378 NULL,
380
381 return (hDevInfo != INVALID_HANDLE_VALUE);
382}
CONFIGRET WINAPI CM_Enumerate_Classes(_In_ ULONG ulClassIndex, _Out_ LPGUID ClassGuid, _In_ ULONG ulFlags)
Definition: cfgmgr.c:2077
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2292
#define DIGCF_PRESENT
Definition: setupapi.h:172

Referenced by ListDevicesByType(), and RefreshDeviceList().

◆ GetNode()

CNode * CDeviceView::GetNode ( _In_ LPTV_ITEMW  TvItem)
private

Definition at line 1285 of file DeviceView.cpp.

1288{
1289 TvItem->mask = TVIF_PARAM;
1290 if (TreeView_GetItem(m_hTreeView, TvItem))
1291 {
1292 return (CNode *)TvItem->lParam;
1293 }
1294 return nullptr;
1295}
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3495
#define TVIF_PARAM
Definition: commctrl.h:3273

Referenced by GetSelectedNode().

◆ GetSelectedNode()

CNode * CDeviceView::GetSelectedNode ( )

Definition at line 341 of file DeviceView.cpp.

342{
343 TV_ITEM TvItem;
344 TvItem.hItem = TreeView_GetSelection(m_hTreeView);
345 return GetNode(&TvItem);
346}
CNode * GetNode(_In_ LPTV_ITEMW TvItem)
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3478
#define TV_ITEM
Definition: commctrl.h:3305

Referenced by CreateActionMenu(), DisplayPropertySheet(), EnableSelectedDevice(), OnContextMenu(), UninstallSelectedDevice(), UpdateSelectedDevice(), and CDeviceManager::UpdateToolbar().

◆ GetSiblingDevice()

bool CDeviceView::GetSiblingDevice ( _In_ DEVINST  PrevDevice,
_Out_ PDEVINST  DevInst 
)
private

Definition at line 968 of file DeviceView.cpp.

972{
973 CONFIGRET cr;
974 cr = CM_Get_Sibling(DevInst,
975 PrevDevice,
976 0);
977 return (cr == CR_SUCCESS);
978}
CONFIGRET WINAPI CM_Get_Sibling(_Out_ PDEVINST pdnDevInst, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags)
Definition: cfgmgr.c:5695

Referenced by RecurseChildDevices(), and RecurseResources().

◆ Initialize()

bool CDeviceView::Initialize ( )

Definition at line 54 of file DeviceView.cpp.

55{
56 // Get the device image list
59 if (bSuccess == FALSE)
60 return false;
61
62 // Create the main treeview
65 NULL,
68 0, 0, 0, 0,
72 NULL);
73 if (m_hTreeView)
74 {
75 // Set the image list against the treeview
79
80 // Give the treeview arrows instead of +/- boxes (on Win7)
81 SetWindowTheme(m_hTreeView, L"explorer", NULL);
82
83 // Create the root node
86 }
87
88
89
90 return !!(m_hTreeView);
91}
virtual bool SetupNode()
Definition: RootNode.cpp:27
#define IDC_TREEVIEW
Definition: resource.h:13
BOOL WINAPI SetupDiGetClassImageList(OUT PSP_CLASSIMAGELIST_DATA ClassImageListData)
Definition: devclass.c:322
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
#define WS_CHILD
Definition: pedump.c:617
#define WS_BORDER
Definition: pedump.c:625
#define WS_VISIBLE
Definition: pedump.c:620
#define TVS_LINESATROOT
Definition: commctrl.h:3254
#define TVSIL_NORMAL
Definition: commctrl.h:3448
#define TVS_SHOWSELALWAYS
Definition: commctrl.h:3257
#define TVS_HASLINES
Definition: commctrl.h:3253
#define WC_TREEVIEW
Definition: commctrl.h:3250
#define TVS_HASBUTTONS
Definition: commctrl.h:3252
#define TreeView_SetImageList(hwnd, himl, iImage)
Definition: commctrl.h:3452
struct _SP_CLASSIMAGELIST_DATA SP_CLASSIMAGELIST_DATA
HRESULT WINAPI SetWindowTheme(_In_ HWND hwnd, _In_ LPCWSTR pszSubAppName, _In_ LPCWSTR pszSubIdList)
Definition: uxthemesupp.c:69
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384

Referenced by CDeviceManager::OnCreate().

◆ InsertIntoTreeView()

HTREEITEM CDeviceView::InsertIntoTreeView ( _In_opt_ HTREEITEM  hParent,
_In_ CNode Node 
)
private

Definition at line 981 of file DeviceView.cpp.

985{
986 LPWSTR lpLabel;
987 lpLabel = Node->GetDisplayName();
988
989 TV_ITEMW tvi;
990 TV_INSERTSTRUCT tvins;
991 ZeroMemory(&tvi, sizeof(tvi));
992 ZeroMemory(&tvins, sizeof(tvins));
993
995 tvi.pszText = lpLabel;
996 tvi.cchTextMax = wcslen(lpLabel);
997 tvi.lParam = (LPARAM)Node;
998 tvi.iImage = Node->GetClassImage();
999 tvi.iSelectedImage = Node->GetClassImage();
1000
1001 // try to cast it to a device node. This will only succeed if it's the correct type
1002 CDeviceNode *DeviceNode = dynamic_cast<CDeviceNode *>(Node);
1003 if (DeviceNode && DeviceNode->GetOverlayImage())
1004 {
1005 tvi.mask |= TVIF_STATE;
1006 tvi.stateMask = TVIS_OVERLAYMASK;
1007 tvi.state = INDEXTOOVERLAYMASK(DeviceNode->GetOverlayImage());
1008 }
1009
1010 tvins.item = tvi;
1011 tvins.hParent = hParent;
1012
1013 return TreeView_InsertItem(m_hTreeView, &tvins);
1014}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LONG_PTR LPARAM
Definition: minwindef.h:175
#define TVIF_TEXT
Definition: commctrl.h:3271
#define TVIF_IMAGE
Definition: commctrl.h:3272
#define TV_INSERTSTRUCT
Definition: commctrl.h:3382
#define TV_ITEMW
Definition: commctrl.h:3302
#define TVIS_OVERLAYMASK
Definition: commctrl.h:3292
#define INDEXTOOVERLAYMASK(i)
Definition: commctrl.h:425
#define TreeView_InsertItem(hwnd, lpis)
Definition: commctrl.h:3417
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3276
#define TVIF_STATE
Definition: commctrl.h:3274
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by AddRootDevice(), ListDevicesByType(), ListResourcesByType(), RecurseChildDevices(), and RecurseResources().

◆ ListDevicesByConnection()

bool CDeviceView::ListDevicesByConnection ( )
private

Definition at line 577 of file DeviceView.cpp.

578{
579 // Walk the device tree and add all the devices
581
582 // Expand the root item
585 TVE_EXPAND);
586
587 return true;
588}
bool RecurseChildDevices(_In_ DEVINST ParentDevice, _In_ HTREEITEM hParentTreeItem)
Definition: DeviceView.cpp:765
DEVINST GetDeviceInst()
Definition: RootNode.h:15
#define TreeView_Expand(hwnd, hitem, code)
Definition: commctrl.h:3425
#define TVE_EXPAND
Definition: commctrl.h:3428

◆ ListDevicesByType()

bool CDeviceView::ListDevicesByType ( )
private

Definition at line 445 of file DeviceView.cpp.

446{
449 HDEVINFO hDevInfo;
450 HTREEITEM hTreeItem = NULL;
451 GUID ClassGuid;
452 INT ClassIndex;
453 BOOL bClassSuccess, bSuccess;
454
455 ClassIndex = 0;
456 do
457 {
458 // Loop through all the device classes
459 bClassSuccess = GetNextClass(ClassIndex, &ClassGuid, &hDevInfo);
460 if (bClassSuccess)
461 {
462 bool AddedParent = false;
463 INT DeviceIndex = 0;
464 bool MoreItems = false;
465
466 // Get the cached class node
467 ClassNode = GetClassNode(&ClassGuid);
468 if (ClassNode == nullptr)
469 {
470 ClassIndex++;
471 continue;
472 }
473
474 // Check if this is a hidden class
475 if (IsEqualGUID(ClassGuid, GUID_DEVCLASS_LEGACYDRIVER) ||
476 IsEqualGUID(ClassGuid, GUID_DEVCLASS_VOLUME))
477 {
478 // Ignore this device if we aren't displaying hidden devices
479 if (m_ShowHidden == FALSE)
480 {
481 ClassIndex++;
482 continue;
483 }
484 }
485
486 do
487 {
488 // Get a handle to all the devices in this class
492 bSuccess = SetupDiEnumDeviceInfo(hDevInfo,
493 DeviceIndex,
495 if (bSuccess == FALSE && GetLastError() == ERROR_NO_MORE_ITEMS)
496 MoreItems = false;
497
498 if (bSuccess)
499 {
500 MoreItems = true;
501
502 // Get the cached device node
504 if (DeviceNode == nullptr)
505 {
506 DeviceIndex++;
507 continue;
508 }
509
510 // Check if this is a hidden device
511 if (DeviceNode->IsHidden())
512 {
513 // Ignore this device if we aren't displaying hidden devices
514 if (m_ShowHidden == FALSE)
515 {
516 DeviceIndex++;
517 continue;
518 }
519 }
520
521 // We have a device, we need to add the parent if it hasn't yet been added
522 if (AddedParent == false)
523 {
524 // Insert the new class under the root item
526 ClassNode);
527 AddedParent = true;
528 }
529
530 // Add the device under the class item node
532
533 // Expand the class if it has a problem device
534 if (DeviceNode->HasProblem())
535 {
537 hTreeItem,
538 TVE_EXPAND);
539 }
540 }
541
542 DeviceIndex++;
543
544 } while (MoreItems);
545
546 // If this class has devices, sort them alphabetically
547 if (AddedParent == true)
548 {
550 hTreeItem,
551 0);
552 }
553 }
554
555 ClassIndex++;
556
557 } while (bClassSuccess);
558
559 // Sort the classes alphabetically
562 0);
563
564 // Expand the root item
567 TVE_EXPAND);
568
569 // Pre-select the root item
572
573 return 0;
574}
bool GetNextClass(_In_ ULONG ClassIndex, _Out_ LPGUID ClassGuid, _Out_ HDEVINFO *hDevInfo)
Definition: DeviceView.cpp:360
CDeviceNode * GetDeviceNode(_In_ DEVINST Device)
CClassNode * GetClassNode(_In_ LPGUID ClassGuid)
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1787
#define TreeView_SelectItem(hwnd, hitem)
Definition: commctrl.h:3486
#define TreeView_SortChildren(hwnd, hitem, recurse)
Definition: commctrl.h:3547
_In_opt_ PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1529
struct _SP_DEVINFO_DATA SP_DEVINFO_DATA
int32_t INT
Definition: typedefs.h:58
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ ListResourcesByType()

bool CDeviceView::ListResourcesByType ( )
private

Definition at line 591 of file DeviceView.cpp.

592{
593 HTREEITEM hMemoryTreeItem = NULL;
594 HTREEITEM hPortTreeItem = NULL;
595 HTREEITEM hDmaTreeItem = NULL;
596 HTREEITEM hIrqTreeItem = NULL;
597
599 hMemoryTreeItem = InsertIntoTreeView(m_hTreeRoot,
600 MemoryNode);
601
603 hPortTreeItem = InsertIntoTreeView(m_hTreeRoot,
604 PortNode);
605
607 hDmaTreeItem = InsertIntoTreeView(m_hTreeRoot,
608 DmaNode);
609
611 hIrqTreeItem = InsertIntoTreeView(m_hTreeRoot,
612 IrqNode);
613
614 // Walk the device tree and add all the resources
616 hMemoryTreeItem,
617 hPortTreeItem,
618 hDmaTreeItem,
619 hIrqTreeItem);
620
621 // Sort the resource types alphabetically
624 0);
625
626 // Expand the root item
629 TVE_EXPAND);
630
631 return true;
632}
#define IDS_TYPE_DMA
Definition: resource.h:221
#define IDS_TYPE_PORT
Definition: resource.h:218
#define IDS_TYPE_MEMORY
Definition: resource.h:220
bool RecurseResources(_In_ DEVINST ParentDevice, _In_ HTREEITEM hMemoryTreeItem, _In_ HTREEITEM hPortTreeItem, _In_ HTREEITEM hDmaTreeItem, _In_ HTREEITEM hIrqTreeItem)
Definition: DeviceView.cpp:636
#define IDS_TYPE_IRQ
Definition: resource.h:97

◆ OnAction()

LRESULT CDeviceView::OnAction ( UINT  Action)

Definition at line 243 of file DeviceView.cpp.

246{
247 switch (Action)
248 {
249 case IDM_PROPERTIES:
250 {
252 break;
253 }
254
256 {
258 true,
259 true);
260 break;
261 }
262
263 case IDM_ENABLE_DRV:
264 {
265 bool NeedsReboot;
266 if (EnableSelectedDevice(true, NeedsReboot) &&
267 NeedsReboot)
268 {
269 MessageBox(m_hMainWnd, L"Rebooting", L"Enable", MB_OK);
270 }
271 break;
272 }
273
274 case IDM_DISABLE_DRV:
275 {
276 bool NeedsReboot;
277 EnableSelectedDevice(false, NeedsReboot);
278 break;
279 }
280
281 case IDM_UPDATE_DRV:
282 {
283 bool NeedsReboot;
284 UpdateSelectedDevice(NeedsReboot);
285 break;
286 }
287
289 {
291 break;
292 }
293
294 case IDM_ADD_HARDWARE:
295 {
297 break;
298 }
299 }
300
301 return 0;
302}
bool RunAddHardwareWizard()
Definition: DeviceView.cpp:931
VOID DisplayPropertySheet()
Definition: DeviceView.cpp:305
bool EnableSelectedDevice(_In_ bool Enable, _Out_ bool &NeedsReboot)
Definition: DeviceView.cpp:861
bool UninstallSelectedDevice()
Definition: DeviceView.cpp:908
ViewType GetCurrentView()
Definition: DeviceView.h:80
bool UpdateSelectedDevice(_Out_ bool &NeedsReboot)
Definition: DeviceView.cpp:889
void Refresh(void)
Definition: magnifier.c:317
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
#define MB_OK
Definition: winuser.h:801
#define MessageBox
Definition: winuser.h:5933

Referenced by CDeviceManager::OnCommand().

◆ OnContextMenu()

LRESULT CDeviceView::OnContextMenu ( _In_ LPARAM  lParam)

Definition at line 169 of file DeviceView.cpp.

172{
174
175 RECT rc;
177 hSelected,
178 &rc,
179 TRUE))
180 {
181 POINT pt;
182 if (GetCursorPos(&pt) &&
184 PtInRect(&rc, pt))
185 {
187 if (Node)
188 {
189 // Create the context menu
190 HMENU hContextMenu = CreatePopupMenu();
191
192 // Add the actions for this node
193 BuildActionMenuForNode(hContextMenu, Node, false);
194
195 INT xPos = GET_X_LPARAM(lParam);
196 INT yPos = GET_Y_LPARAM(lParam);
197
198 // Display the menu
199 TrackPopupMenuEx(hContextMenu,
201 xPos,
202 yPos,
204 NULL);
205
206 DestroyMenu(hContextMenu);
207 }
208 }
209 }
210
211 return 0;
212}
LPARAM lParam
Definition: combotst.c:139
#define pt(x, y)
Definition: drawing.c:79
#define TreeView_GetItemRect(hwnd, hitem, prc, code)
Definition: commctrl.h:3434
Definition: windef.h:99
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:300
#define GET_X_LPARAM(lp)
Definition: windowsx.h:299
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
#define TPM_RIGHTBUTTON
Definition: winuser.h:2416
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:3047
BOOL WINAPI TrackPopupMenuEx(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _In_ HWND, _In_opt_ LPTPMPARAMS)
BOOL WINAPI PtInRect(_In_ LPCRECT, _In_ POINT)
BOOL WINAPI DestroyMenu(_In_ HMENU)
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)

Referenced by CDeviceManager::OnContext().

◆ OnDoubleClick()

LRESULT CDeviceView::OnDoubleClick ( _In_ LPNMHDR  NmHdr)

Definition at line 128 of file DeviceView.cpp.

131{
132 TVHITTESTINFO hitInfo;
134
135 GetCursorPos(&hitInfo.pt);
136 ScreenToClient(m_hTreeView, &hitInfo.pt);
137
138 // Check if we are trying to double-click an item
140 if (hItem != NULL && (hitInfo.flags & (TVHT_ONITEM | TVHT_ONITEMICON)))
141 {
143 }
144
145 return 0;
146}
#define TVHT_ONITEM
Definition: commctrl.h:3532
#define TVHT_ONITEMICON
Definition: commctrl.h:3530
#define TreeView_HitTest(hwnd, lpht)
Definition: commctrl.h:3518
HTREEITEM hItem
Definition: treelist.h:37

Referenced by CDeviceManager::OnNotify().

◆ OnRightClick()

LRESULT CDeviceView::OnRightClick ( _In_ LPNMHDR  NmHdr)

Definition at line 149 of file DeviceView.cpp.

152{
153 TVHITTESTINFO hitInfo;
155
156 GetCursorPos(&hitInfo.pt);
157 ScreenToClient(m_hTreeView, &hitInfo.pt);
158
160 if (hItem != NULL && (hitInfo.flags & (TVHT_ONITEM | TVHT_ONITEMICON)))
161 {
163 }
164
165 return 0;
166}

Referenced by CDeviceManager::OnNotify().

◆ OnSize()

LRESULT CDeviceView::OnSize ( _In_ int  x,
_In_ int  y,
_In_ int  cx,
_In_ int  cy 
)

Definition at line 108 of file DeviceView.cpp.

114{
115 // Resize the treeview
117 NULL,
118 x,
119 y,
120 cx,
121 cy,
123
124 return 0;
125}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOZORDER
Definition: winuser.h:1258

Referenced by CDeviceManager::OnSize().

◆ RecurseChildDevices()

bool CDeviceView::RecurseChildDevices ( _In_ DEVINST  ParentDevice,
_In_ HTREEITEM  hParentTreeItem 
)
private

Definition at line 765 of file DeviceView.cpp.

769{
770 HTREEITEM hDevItem = NULL;
772 bool HasProblem = false;
773 bool bSuccess;
774
775 // Check if the parent has any child devices
777 return true;
778
779 // Get the cached device node
781 DeviceNode = dynamic_cast<CDeviceNode *>(GetDeviceNode(Device));
782 if (DeviceNode == nullptr)
783 {
784 return false;
785 }
786
787 // Don't show hidden devices if not requested
788 if ((m_ShowHidden == TRUE) || (!(DeviceNode->IsHidden())))
789 {
790 // Add this device to the tree under its parent
791 hDevItem = InsertIntoTreeView(hParentTreeItem,
792 DeviceNode);
793 if (hDevItem)
794 {
795 // Check if this child has any children itself
796 if (!RecurseChildDevices(Device, hDevItem))
797 HasProblem = true;
798 }
799
800 if (DeviceNode->HasProblem())
801 {
802 HasProblem = true;
803 }
804 }
805
806
807 // Check for siblings
808 for (;;)
809 {
810 // Check if the parent device has anything at the same level
811 bSuccess = GetSiblingDevice(Device, &Device);
812 if (bSuccess == FALSE)
813 break;
814
815 DeviceNode = dynamic_cast<CDeviceNode *>(GetDeviceNode(Device));
816 if (DeviceNode == nullptr)
817 {
818 continue;
819 }
820
821 // Don't show hidden devices if not requested
822 if ((m_ShowHidden == TRUE) || (!(DeviceNode->IsHidden())))
823 {
824 if (DeviceNode->HasProblem())
825 {
826 HasProblem = true;
827 }
828
829 // Add this device to the tree under its parent
830 hDevItem = InsertIntoTreeView(hParentTreeItem,
831 DeviceNode);
832 if (hDevItem)
833 {
834 // Check if this child has any children itself
835 if (!RecurseChildDevices(Device, hDevItem))
836 HasProblem = true;
837 }
838 }
839 }
840
842 hParentTreeItem,
843 0);
844
845 // Expand the class if it has a problem device
846 if (HasProblem == true)
847 {
849 hParentTreeItem,
850 TVE_EXPAND);
851 }
852
853 // If there was a problem, expand the ancestors
854 if (HasProblem)
855 return false;
856
857 return true;
858}
DWORD DEVINST
Definition: cfgmgr32.h:76
bool GetChildDevice(_In_ DEVINST ParentDevInst, _Out_ PDEVINST DevInst)
Definition: DeviceView.cpp:955
bool GetSiblingDevice(_In_ DEVINST PrevDevice, _Out_ PDEVINST DevInst)
Definition: DeviceView.cpp:968
_Must_inspect_result_ _In_ WDFDEVICE ParentDevice
Definition: wdfpdo.h:220

Referenced by ListDevicesByConnection(), and RecurseChildDevices().

◆ RecurseFindDevice()

HTREEITEM CDeviceView::RecurseFindDevice ( _In_ HTREEITEM  hParentItem,
_In_ CNode Node 
)
private

Definition at line 1114 of file DeviceView.cpp.

1118{
1119 HTREEITEM FoundItem;
1121 TVITEMW tvItem;
1122 CNode *FoundNode;
1123
1124 // Check if this node has any children
1125 hItem = TreeView_GetChild(m_hTreeView, hParentItem);
1126 if (hItem == NULL)
1127 return NULL;
1128
1129 // The lParam contains the node pointer data
1130 tvItem.hItem = hItem;
1131 tvItem.mask = TVIF_PARAM;
1132 if (TreeView_GetItem(m_hTreeView, &tvItem) &&
1133 tvItem.lParam != NULL)
1134 {
1135 // check for a matching node
1136 FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
1137 if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
1138 (IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
1139 {
1140 // check if this is a class node, or a device with matching ID's
1141 if ((FoundNode->GetNodeType() == ClassNode) ||
1142 (wcscmp(FoundNode->GetDeviceId(), Node->GetDeviceId()) == 0))
1143 {
1144 return hItem;
1145 }
1146 }
1147 }
1148
1149 // This node may have its own children
1150 FoundItem = RecurseFindDevice(hItem, Node);
1151 if (FoundItem)
1152 return FoundItem;
1153
1154 // Loop all the siblings
1155 for (;;)
1156 {
1157 // Get the next item at this level
1159 if (hItem == NULL)
1160 break;
1161
1162 // The lParam contains the node pointer data
1163 tvItem.hItem = hItem;
1164 tvItem.mask = TVIF_PARAM;
1165 if (TreeView_GetItem(m_hTreeView, &tvItem))
1166 {
1167 // check for a matching class
1168 FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
1169 if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
1170 (IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
1171 {
1172 // check if this is a class node, or a device with matching ID's
1173 if ((FoundNode->GetNodeType() == ClassNode) ||
1174 (wcscmp(FoundNode->GetDeviceId(), Node->GetDeviceId()) == 0))
1175 {
1176 return hItem;
1177 }
1178 }
1179 }
1180
1181 // This node may have its own children
1182 FoundItem = RecurseFindDevice(hItem, Node);
1183 if (FoundItem)
1184 return FoundItem;
1185 }
1186
1187 return hItem;
1188}
HTREEITEM RecurseFindDevice(_In_ HTREEITEM hParentItem, _In_ CNode *Node)
LPGUID GetClassGuid()
Definition: Node.h:39
LPWSTR GetDeviceId()
Definition: Node.h:42
NodeType GetNodeType()
Definition: Node.h:38
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3471
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3472
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
HTREEITEM hItem
Definition: commctrl.h:3322
LPARAM lParam
Definition: commctrl.h:3330
UINT mask
Definition: commctrl.h:3321

Referenced by RecurseFindDevice(), and SelectNode().

◆ RecurseResources()

bool CDeviceView::RecurseResources ( _In_ DEVINST  ParentDevice,
_In_ HTREEITEM  hMemoryTreeItem,
_In_ HTREEITEM  hPortTreeItem,
_In_ HTREEITEM  hDmaTreeItem,
_In_ HTREEITEM  hIrqTreeItem 
)
private

Definition at line 636 of file DeviceView.cpp.

643{
645 bool bSuccess;
646 ULONG Index;
647
648 // Check if the parent has any child devices
650 return true;
651
652 // Get the cached device node
654 DeviceNode = dynamic_cast<CDeviceNode *>(GetDeviceNode(Device));
655 if (DeviceNode == nullptr)
656 {
657 return false;
658 }
659
660 PCM_RESOURCE_LIST pResourceList = (PCM_RESOURCE_LIST)GetResourceList(DeviceNode->GetDeviceId());
661 if (pResourceList)
662 {
663
664 for (Index = 0; Index < pResourceList->List[0].PartialResourceList.Count; Index++)
665 {
667
669 {
671 InsertIntoTreeView(hIrqTreeItem, resNode);
672 }
673 else if (Descriptor->Type == CmResourceTypePort)
674 {
676 InsertIntoTreeView(hPortTreeItem, resNode);
677 }
678 else if (Descriptor->Type == CmResourceTypeMemory)
679 {
681 InsertIntoTreeView(hMemoryTreeItem, resNode);
682 }
683 else if (Descriptor->Type == CmResourceTypeDma)
684 {
686 InsertIntoTreeView(hDmaTreeItem, resNode);
687 }
688 }
689
690 HeapFree(GetProcessHeap(), 0, pResourceList);
691 }
692
693 RecurseResources(Device, hMemoryTreeItem, hPortTreeItem, hDmaTreeItem, hIrqTreeItem);
694
695 // Check for siblings
696 for (;;)
697 {
698 // Check if the parent device has anything at the same level
699 bSuccess = GetSiblingDevice(Device, &Device);
700 if (bSuccess == FALSE)
701 break;
702
703 DeviceNode = dynamic_cast<CDeviceNode *>(GetDeviceNode(Device));
704 if (DeviceNode == nullptr)
705 {
706 continue;
707 }
708
709 PCM_RESOURCE_LIST pResourceList = (PCM_RESOURCE_LIST)GetResourceList(DeviceNode->GetDeviceId());
710 if (pResourceList)
711 {
712 for (Index = 0; Index < pResourceList->List[0].PartialResourceList.Count; Index++)
713 {
715
717 {
719 InsertIntoTreeView(hIrqTreeItem, resNode);
720 }
721 else if (Descriptor->Type == CmResourceTypePort)
722 {
724 InsertIntoTreeView(hPortTreeItem, resNode);
725 }
726 else if (Descriptor->Type == CmResourceTypeMemory)
727 {
729 InsertIntoTreeView(hMemoryTreeItem, resNode);
730 }
731 else if (Descriptor->Type == CmResourceTypeDma)
732 {
734 InsertIntoTreeView(hDmaTreeItem, resNode);
735 }
736 }
737
738 HeapFree(GetProcessHeap(), 0, pResourceList);
739 }
740
741 RecurseResources(Device, hMemoryTreeItem, hPortTreeItem, hDmaTreeItem, hIrqTreeItem);
742 }
743
745 hMemoryTreeItem,
746 0);
747
749 hPortTreeItem,
750 0);
751
753 hIrqTreeItem,
754 0);
755
757 hDmaTreeItem,
758 0);
759
760 return true;
761}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
PVOID GetResourceList(LPWSTR pszDeviceID)
Definition: hwresource.cpp:299
#define CmResourceTypeMemory
Definition: restypes.h:106
struct _CM_RESOURCE_LIST * PCM_RESOURCE_LIST
#define CmResourceTypeDma
Definition: restypes.h:107
#define CmResourceTypePort
Definition: restypes.h:104
#define CmResourceTypeInterrupt
Definition: restypes.h:105
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: restypes.h:144
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
CM_FULL_RESOURCE_DESCRIPTOR List[1]
Definition: restypes.h:149
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

Referenced by ListResourcesByType(), and RecurseResources().

◆ Refresh()

void CDeviceView::Refresh ( _In_ ViewType  Type,
_In_ bool  ScanForChanges,
_In_ bool  UpdateView 
)

Definition at line 216 of file DeviceView.cpp.

221{
222 // Enum devices on a separate thread to keep the gui responsive
223
225
228 ThreadData->This = this;
229 ThreadData->ScanForChanges = ScanForChanges;
230 ThreadData->UpdateView = UpdateView;
231
234 0,
237 0,
238 NULL);
240}
Type
Definition: Type.h:7
static unsigned int __stdcall RefreshThread(void *Param)
Definition: DeviceView.cpp:384
#define CloseHandle
Definition: compat.h:739
HANDLE hThread
Definition: wizard.c:28
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
static void UpdateView(TreeListData *pData)
Definition: treelist.c:1636
PVOID HANDLE
Definition: typedefs.h:73

Referenced by CDeviceManager::RefreshView().

◆ RefreshDeviceList()

bool CDeviceView::RefreshDeviceList ( )
private

Definition at line 1316 of file DeviceView.cpp.

1317{
1318 GUID ClassGuid;
1321 HDEVINFO hDevInfo;
1323 DWORD i;
1324 BOOL Success;
1325
1326 ULONG ClassIndex = 0;
1327
1328 EmptyLists();
1329
1330 if (m_RootNode) delete m_RootNode;
1333
1334 // Loop through all the classes
1335 do
1336 {
1337 Success = GetNextClass(ClassIndex, &ClassGuid, &hDevInfo);
1338 if (Success)
1339 {
1340 // Create a new class node and add it to the list
1341 ClassNode = new CClassNode(&ClassGuid, &m_ImageListData);
1342 if (ClassNode->SetupNode())
1343 {
1344 m_ClassNodeList.AddTail(ClassNode);
1345 }
1346
1348 }
1349 ClassIndex++;
1350 } while (Success);
1351
1352 // Get all the devices on the local machine
1353 hDevInfo = SetupDiGetClassDevsW(NULL,
1354 0,
1355 0,
1357 if (hDevInfo == INVALID_HANDLE_VALUE)
1358 {
1359 return false;
1360 }
1361
1362 // loop though all the devices
1364 for (i = 0;; i++)
1365 {
1366 // Get the devinst for this device
1368 if (Success == FALSE)
1369 break;
1370
1371 // create a new device node and add it to the list
1373 if (DeviceNode->SetupNode())
1374 {
1376 }
1377 else
1378 {
1380 }
1381 }
1382
1384
1385 return TRUE;
1386}
void EmptyLists()
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2893
@ Success
Definition: eventcreate.c:712
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DIGCF_ALLCLASSES
Definition: setupapi.h:173

◆ RefreshThread()

unsigned int __stdcall CDeviceView::RefreshThread ( void Param)
staticprivate

Definition at line 384 of file DeviceView.cpp.

385{
387 CDeviceView *This = ThreadData->This;
388
389 // Get a copy of the currently selected node
390 CNode *LastSelectedNode = This->GetSelectedNode();
391 if (LastSelectedNode == nullptr || (LastSelectedNode->GetNodeType() == RootNode))
392 {
393 LastSelectedNode = new CRootNode(*This->m_RootNode);
394 }
395 else if (LastSelectedNode->GetNodeType() == ClassNode)
396 {
397 LastSelectedNode = new CClassNode(*dynamic_cast<CClassNode *>(LastSelectedNode));
398 }
399 else if (LastSelectedNode->GetNodeType() == DeviceNode)
400 {
401 LastSelectedNode = new CDeviceNode(*dynamic_cast<CDeviceNode *>(LastSelectedNode));
402 }
403
404 // Empty the treeview
405 This->EmptyDeviceView();
406
407 // Re-add the root node to the tree
408 if (This->AddRootDevice() == false)
409 return 0;
410
411 // Refresh the devices only if requested
412 if (ThreadData->ScanForChanges)
413 {
414 This->RefreshDeviceList();
415 }
416
417 // display the type of view the user wants
418 switch (This->m_ViewType)
419 {
420 case DevicesByType:
421 (void)This->ListDevicesByType();
422 break;
423
425 (VOID)This->ListDevicesByConnection();
426 break;
427
428 case ResourcesByType:
429 (VOID)This->ListResourcesByType();
430 break;
431
433 break;
434 }
435
436 This->SelectNode(LastSelectedNode);
437
438 delete ThreadData;
439
440 return 0;
441}
@ DevicesByConnection
Definition: DeviceView.h:11
@ ResourcesByType
Definition: DeviceView.h:12
@ ResourcesByConnection
Definition: DeviceView.h:13

Referenced by Refresh().

◆ RunAddHardwareWizard()

bool CDeviceView::RunAddHardwareWizard ( )
private

Definition at line 931 of file DeviceView.cpp.

932{
933 PADDHARDWAREWIZARD pAddHardwareWizard;
935
936 hModule = LoadLibraryW(L"hdwwiz.cpl");
937 if (hModule == NULL)
938 return false;
939
940 pAddHardwareWizard = (PADDHARDWAREWIZARD)GetProcAddress(hModule,
941 "AddHardwareWizard");
942 if (pAddHardwareWizard == NULL)
943 {
945 return false;
946 }
947
948 pAddHardwareWizard(m_hMainWnd, NULL);
949
951 return true;
952}
VOID(WINAPI * PADDHARDWAREWIZARD)(HWND hwnd, LPWSTR lpName)
Definition: DeviceView.cpp:23
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
HMODULE hModule
Definition: netsh.c:17

Referenced by OnAction().

◆ SelDeviceIsInstalled()

bool CDeviceView::SelDeviceIsInstalled ( )

◆ SelDeviceIsStarted()

bool CDeviceView::SelDeviceIsStarted ( )

◆ SelectNode()

void CDeviceView::SelectNode ( _In_ CNode Node)
private

Definition at line 1191 of file DeviceView.cpp.

1194{
1196
1197 // Check if there are any items in the tree
1199 if (hRoot == NULL)
1200 return;
1201
1202 // If we don't want to set select a node, just select root
1203 if (Node == nullptr || Node->GetNodeType() == RootNode)
1204 {
1206 return;
1207 }
1208
1209 // Scan the tree looking for the node we want
1211 if (hItem)
1212 {
1214 }
1215 else
1216 {
1218 }
1219}
static HTREEITEM hRoot
Definition: treeview.c:383
#define TreeView_GetRoot(hwnd)
Definition: commctrl.h:3480

◆ SetFocus()

void CDeviceView::SetFocus ( )

Definition at line 319 of file DeviceView.cpp.

320{
322}
VOID SetFocus()
Definition: DeviceView.cpp:319

Referenced by CDeviceManager::OnActivate(), CDeviceManager::OnCommand(), and SetFocus().

◆ SetHiddenDevices()

VOID CDeviceView::SetHiddenDevices ( _In_ bool  ShowHidden)
inline

Definition at line 75 of file DeviceView.h.

76 {
77 m_ShowHidden = ShowHidden;
78 }

Referenced by CDeviceManager::OnCommand().

◆ Uninitialize()

bool CDeviceView::Uninitialize ( )

Definition at line 94 of file DeviceView.cpp.

95{
97
99 {
102 }
103
104 return true;
105}
void EmptyDeviceView()
BOOL WINAPI SetupDiDestroyClassImageList(IN PSP_CLASSIMAGELIST_DATA ClassImageListData)
Definition: devclass.c:85

Referenced by CDeviceManager::OnDestroy().

◆ UninstallSelectedDevice()

bool CDeviceView::UninstallSelectedDevice ( )
private

Definition at line 908 of file DeviceView.cpp.

910{
911 CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
912 if (Node == nullptr)
913 return false;
914
916 if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_UNINSTALL))
917 {
919 str,
920 Node->GetDisplayName(),
922 {
923 return false;
924 }
925 }
926
927 return Node->UninstallDevice();
928}
#define IDS_CONFIRM_UNINSTALL
Definition: resource.h:54

Referenced by OnAction().

◆ UpdateSelectedDevice()

bool CDeviceView::UpdateSelectedDevice ( _Out_ bool NeedsReboot)
private

Definition at line 889 of file DeviceView.cpp.

892{
893 CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
894 if (Node == nullptr)
895 return false;
896
897 DWORD dwReboot;
898 if (InstallDevInst(m_hMainWnd, Node->GetDeviceId(), TRUE, &dwReboot))
899 {
900 NeedsReboot = false;
901 return true;
902 }
903
904 return false;
905}
BOOL WINAPI InstallDevInst(IN HWND hWndParent, IN LPCWSTR InstanceId, IN BOOL bUpdate, OUT LPDWORD lpReboot)
Definition: stubs.cpp:24

Referenced by OnAction().

Member Data Documentation

◆ m_ClassNodeList

CAtlList<CClassNode *> CDeviceView::m_ClassNodeList
private

Definition at line 29 of file DeviceView.h.

Referenced by EmptyLists(), GetClassNode(), and RefreshDeviceList().

◆ m_DeviceNodeList

CAtlList<CDeviceNode *> CDeviceView::m_DeviceNodeList
private

Definition at line 30 of file DeviceView.h.

Referenced by EmptyLists(), GetDeviceNode(), and RefreshDeviceList().

◆ m_hMainWnd

◆ m_hMenu

HMENU CDeviceView::m_hMenu
private

Definition at line 23 of file DeviceView.h.

◆ m_hPropertyDialog

HWND CDeviceView::m_hPropertyDialog
private

Definition at line 22 of file DeviceView.h.

◆ m_hTreeRoot

HTREEITEM CDeviceView::m_hTreeRoot
private

◆ m_hTreeView

◆ m_ImageListData

SP_CLASSIMAGELIST_DATA CDeviceView::m_ImageListData
private

◆ m_RootNode

CRootNode* CDeviceView::m_RootNode
private

◆ m_ShowHidden

bool CDeviceView::m_ShowHidden
private

Definition at line 26 of file DeviceView.h.

Referenced by ListDevicesByType(), RecurseChildDevices(), and SetHiddenDevices().

◆ m_ViewType

ViewType CDeviceView::m_ViewType
private

Definition at line 24 of file DeviceView.h.

Referenced by GetCurrentView(), and Refresh().


The documentation for this class was generated from the following files: