ReactOS  0.4.15-dev-3299-gbe8e5fc
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 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 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 15 of file DeviceView.h.

Constructor & Destructor Documentation

◆ CDeviceView()

CDeviceView::CDeviceView ( HWND  hMainWnd)

Definition at line 35 of file DeviceView.cpp.

37  :
41  m_hMenu(NULL),
43  m_ShowHidden(false),
45 {
47 }
#define ZeroMemory
Definition: winbase.h:1664
ViewType m_ViewType
Definition: DeviceView.h:22
HWND m_hTreeView
Definition: DeviceView.h:19
HWND m_hMainWnd
Definition: DeviceView.h:18
HWND hMainWnd
Definition: magnifier.c:32
HMENU m_hMenu
Definition: DeviceView.h:21
HWND m_hPropertyDialog
Definition: DeviceView.h:20
#define NULL
Definition: types.h:112
bool m_ShowHidden
Definition: DeviceView.h:24
SP_CLASSIMAGELIST_DATA m_ImageListData
Definition: DeviceView.h:29
CRootNode * m_RootNode
Definition: DeviceView.h:26

◆ ~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 332 of file DeviceView.cpp.

333 {
335  return (m_hTreeRoot != NULL);
336 }
HTREEITEM m_hTreeRoot
Definition: DeviceView.h:23
HTREEITEM InsertIntoTreeView(_In_opt_ HTREEITEM hParent, _In_ CNode *Node)
Definition: DeviceView.cpp:785
#define NULL
Definition: types.h:112
CRootNode * m_RootNode
Definition: DeviceView.h:26

◆ BuildActionMenuForNode()

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

Definition at line 821 of file DeviceView.cpp.

826 {
827  // Create a separator structure
828  MENUITEMINFOW MenuSeparator = { 0 };
829  MenuSeparator.cbSize = sizeof(MENUITEMINFOW);
830  MenuSeparator.fType = MFT_SEPARATOR;
831 
832  // Setup the
833  MENUITEMINFOW MenuItemInfo = { 0 };
834  MenuItemInfo.cbSize = sizeof(MENUITEMINFOW);
835  MenuItemInfo.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA | MIIM_SUBMENU;
836  MenuItemInfo.fType = MFT_STRING;
837 
839  int i = 0;
840 
841  // Device nodes have extra data
842  if (Node->GetNodeType() == DeviceNode)
843  {
844  CDeviceNode *DeviceNode = dynamic_cast<CDeviceNode *>(Node);
845 
846  if (DeviceNode->CanUpdate())
847  {
848  String.LoadStringW(g_hThisInstance, IDS_MENU_UPDATE);
849  MenuItemInfo.wID = IDM_UPDATE_DRV;
850  MenuItemInfo.dwTypeData = String.GetBuffer();
851  InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
852  i++;
853  }
854 
855  if (DeviceNode->IsDisabled())
856  {
857  String.LoadStringW(g_hThisInstance, IDS_MENU_ENABLE);
858  MenuItemInfo.wID = IDM_ENABLE_DRV;
859  MenuItemInfo.dwTypeData = String.GetBuffer();
860  InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
861  i++;
862  }
863 
864  if (DeviceNode->CanDisable() && !DeviceNode->IsDisabled())
865  {
867  MenuItemInfo.wID = IDM_DISABLE_DRV;
868  MenuItemInfo.dwTypeData = String.GetBuffer();
869  InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
870  i++;
871  }
872 
873  if (DeviceNode->CanUninstall())
874  {
876  MenuItemInfo.wID = IDM_UNINSTALL_DRV;
877  MenuItemInfo.dwTypeData = String.GetBuffer();
878  InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
879  i++;
880  }
881 
882  InsertMenuItemW(OwnerMenu, i, TRUE, &MenuSeparator);
883  i++;
884  }
885 
886  // All nodes have the scan option
887  String.LoadStringW(g_hThisInstance, IDS_MENU_SCAN);
888  MenuItemInfo.wID = IDM_SCAN_HARDWARE;
889  MenuItemInfo.dwTypeData = String.GetBuffer();
890  InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
891  i++;
892 
893  if ((Node->GetNodeType() == RootNode) || (MainMenu == true))
894  {
895  String.LoadStringW(g_hThisInstance, IDS_MENU_ADD);
896  MenuItemInfo.wID = IDM_ADD_HARDWARE;
897  MenuItemInfo.dwTypeData = String.GetBuffer();
898  InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
899  i++;
900  }
901 
902  if (Node->HasProperties())
903  {
904  InsertMenuItemW(OwnerMenu, i, TRUE, &MenuSeparator);
905  i++;
906 
908  MenuItemInfo.wID = IDM_PROPERTIES;
909  MenuItemInfo.dwTypeData = String.GetBuffer();
910  InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
911  i++;
912 
914  }
915 }
#define IDS_MENU_ADD
Definition: resource.h:62
#define IDM_UPDATE_DRV
Definition: resource.h:26
#define MFT_STRING
Definition: winuser.h:741
#define TRUE
Definition: types.h:120
#define IDS_MENU_SCAN
Definition: resource.h:61
HINSTANCE g_hThisInstance
Definition: MainWindow.cpp:25
LPWSTR dwTypeData
Definition: winuser.h:3245
#define MIIM_SUBMENU
Definition: winuser.h:718
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
#define FALSE
Definition: types.h:117
#define IDM_UNINSTALL_DRV
Definition: resource.h:27
#define MIIM_ID
Definition: winuser.h:717
CStringT< wchar_t, StrTraitATL< wchar_t, ChTraitsCRT< wchar_t > > > CAtlStringW
Definition: atlstr.h:126
#define IDC_PROPERTIES
Definition: resource.h:32
#define IDM_ADD_HARDWARE
Definition: resource.h:28
Definition: Node.h:9
#define MFT_SEPARATOR
Definition: winuser.h:739
#define IDM_PROPERTIES
Definition: resources.h:9
#define IDS_MENU_DISABLE
Definition: resource.h:59
#define MIIM_STRING
Definition: winuser.h:722
#define IDM_SCAN_HARDWARE
Definition: resource.h:23
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
#define IDM_DISABLE_DRV
Definition: resource.h:25
#define IDS_MENU_ENABLE
Definition: resource.h:58
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
#define IDS_MENU_PROPERTIES
Definition: resource.h:63
BOOL WINAPI SetMenuDefaultItem(_In_ HMENU, _In_ UINT, _In_ UINT)
#define IDS_MENU_UNINSTALL
Definition: resource.h:60
#define IDS_MENU_UPDATE
Definition: resource.h:57
#define MIIM_DATA
Definition: winuser.h:721
struct tagMENUITEMINFOW MENUITEMINFOW
#define IDM_ENABLE_DRV
Definition: resource.h:24
PCONFIGURATION_COMPONENT_DATA RootNode
Definition: macharm.c:19
Definition: dlist.c:348

Referenced by CreateActionMenu(), and OnContextMenu().

◆ CreateActionMenu()

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

Definition at line 304 of file DeviceView.cpp.

308 {
310  if (Node)
311  {
312  BuildActionMenuForNode(OwnerMenu, Node, MainMenu);
313  return true;
314  }
315 
316  return false;
317 }
CNode * GetSelectedNode()
Definition: DeviceView.cpp:320
Definition: Node.h:12
void BuildActionMenuForNode(_In_ HMENU OwnerMenu, _In_ CNode *Node, _In_ bool MainMenu)
Definition: DeviceView.cpp:821
Definition: dlist.c:348

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

◆ DisplayPropertySheet()

void CDeviceView::DisplayPropertySheet ( )

Definition at line 284 of file DeviceView.cpp.

285 {
287  if (Node && Node->HasProperties())
288  {
290  NULL,
291  Node->GetDeviceId(),
292  1,//DPF_EXTENDED,
293  FALSE);
294  }
295 }
HWND m_hTreeView
Definition: DeviceView.h:19
#define FALSE
Definition: types.h:117
CNode * GetSelectedNode()
Definition: DeviceView.cpp:320
Definition: Node.h:12
#define NULL
Definition: types.h:112
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
Definition: dlist.c:348

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

◆ EmptyDeviceView()

void CDeviceView::EmptyDeviceView ( )
private

Definition at line 1027 of file DeviceView.cpp.

1028 {
1030 }
#define TreeView_DeleteAllItems(hwnd)
Definition: commctrl.h:3417
HWND m_hTreeView
Definition: DeviceView.h:19
#define VOID
Definition: acefi.h:82

Referenced by Uninitialize().

◆ EmptyLists()

void CDeviceView::EmptyLists ( )
private

Definition at line 1102 of file DeviceView.cpp.

1103 {
1104  CNode *Node;
1105 
1106  while (!m_ClassNodeList.IsEmpty())
1107  {
1108  Node = m_ClassNodeList.RemoveTail();
1109  delete Node;
1110  }
1111 
1112  while (!m_DeviceNodeList.IsEmpty())
1113  {
1114  Node = m_DeviceNodeList.RemoveTail();
1115  delete Node;
1116  }
1117 }
CAtlList< CClassNode * > m_ClassNodeList
Definition: DeviceView.h:27
CAtlList< CDeviceNode * > m_DeviceNodeList
Definition: DeviceView.h:28
union node Node
Definition: types.h:1255
Definition: Node.h:12
Definition: dlist.c:348

Referenced by RefreshDeviceList().

◆ EnableSelectedDevice()

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

Definition at line 665 of file DeviceView.cpp.

669 {
670  CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
671  if (Node == nullptr)
672  return false;
673 
674  if (Enable == false)
675  {
677  if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_DISABLE))
678  {
680  str,
681  Node->GetDisplayName(),
683  {
684  return false;
685  }
686  }
687  }
688 
689  return Node->EnableDevice(Enable, NeedsReboot);
690 }
#define IDS_CONFIRM_DISABLE
Definition: resource.h:53
#define IDYES
Definition: winuser.h:829
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
HINSTANCE g_hThisInstance
Definition: MainWindow.cpp:25
#define MB_ICONWARNING
Definition: winuser.h:780
#define MB_YESNO
Definition: winuser.h:811
const WCHAR * str
CNode * GetSelectedNode()
Definition: DeviceView.cpp:320
HWND m_hMainWnd
Definition: DeviceView.h:18
CStringT< wchar_t, StrTraitATL< wchar_t, ChTraitsCRT< wchar_t > > > CAtlStringW
Definition: atlstr.h:126
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
#define MB_DEFBUTTON2
Definition: winuser.h:793
Definition: dlist.c:348

Referenced by OnAction().

◆ GetChildDevice()

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

Definition at line 759 of file DeviceView.cpp.

763 {
764  CONFIGRET cr;
765  cr = CM_Get_Child(DevInst,
766  ParentDevInst,
767  0);
768  return (cr == CR_SUCCESS);
769 }
CONFIGRET WINAPI CM_Get_Child(_Out_ PDEVINST pdnDevInst, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags)
Definition: cfgmgr.c:2525
#define CR_SUCCESS
Definition: cfgmgr32.h:842
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74

Referenced by RecurseChildDevices().

◆ GetClassNode()

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

Definition at line 1034 of file DeviceView.cpp.

1037 {
1038  POSITION Pos;
1039  CClassNode *Node = nullptr;
1040 
1041  Pos = m_ClassNodeList.GetHeadPosition();
1042  if (Pos == NULL)
1043  return nullptr;
1044 
1045  do
1046  {
1047  Node = m_ClassNodeList.GetNext(Pos);
1048  if (IsEqualGUID(*Node->GetClassGuid(), *ClassGuid))
1049  {
1050  ATLASSERT(Node->GetNodeType() == ClassNode);
1051  break;
1052  }
1053 
1054  Node = nullptr;
1055 
1056  } while (Pos != NULL);
1057 
1058  return Node;
1059 }
#define ATLASSERT(x)
Definition: CComVariant.cpp:10
CAtlList< CClassNode * > m_ClassNodeList
Definition: DeviceView.h:27
ush Pos
Definition: deflate.h:92
union node Node
Definition: types.h:1255
Definition: Node.h:8
#define NULL
Definition: types.h:112
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
Definition: dlist.c:348

Referenced by ListDevicesByType().

◆ GetCurrentView()

ViewType CDeviceView::GetCurrentView ( )
inline

Definition at line 74 of file DeviceView.h.

74 { return m_ViewType; }
ViewType m_ViewType
Definition: DeviceView.h:22

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

◆ GetDeviceNode()

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

Definition at line 1062 of file DeviceView.cpp.

1065 {
1066  POSITION Pos;
1067  CDeviceNode *Node = nullptr;
1068 
1069  Pos = m_DeviceNodeList.GetHeadPosition();
1070  if (Pos == NULL)
1071  return nullptr;
1072 
1073  do
1074  {
1075  Node = m_DeviceNodeList.GetNext(Pos);
1076  if (Node->GetDeviceInst() == Device)
1077  {
1078  ATLASSERT(Node->GetNodeType() == DeviceNode);
1079  break;
1080  }
1081 
1082  Node = nullptr;
1083 
1084  } while (Pos != NULL);
1085 
1086  return Node;
1087 }
#define ATLASSERT(x)
Definition: CComVariant.cpp:10
ush Pos
Definition: deflate.h:92
CAtlList< CDeviceNode * > m_DeviceNodeList
Definition: DeviceView.h:28
union node Node
Definition: types.h:1255
Definition: Node.h:9
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
#define NULL
Definition: types.h:112
Definition: dlist.c:348

Referenced by ListDevicesByType(), and RecurseChildDevices().

◆ GetNextClass()

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

Definition at line 339 of file DeviceView.cpp.

344 {
345  CONFIGRET cr;
346 
347  // Get the next class in the list
348  cr = CM_Enumerate_Classes(ClassIndex,
349  ClassGuid,
350  0);
351  if (cr != CR_SUCCESS)
352  return false;
353 
354  // We only want the devices for this class
355  *hDevInfo = SetupDiGetClassDevsW(ClassGuid,
356  NULL,
357  NULL,
358  DIGCF_PRESENT);
359 
360  return (hDevInfo != INVALID_HANDLE_VALUE);
361 }
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2288
CONFIGRET WINAPI CM_Enumerate_Classes(_In_ ULONG ulClassIndex, _Out_ LPGUID ClassGuid, _In_ ULONG ulFlags)
Definition: cfgmgr.c:1987
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define CR_SUCCESS
Definition: cfgmgr32.h:842
#define NULL
Definition: types.h:112
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74
#define DIGCF_PRESENT
Definition: setupapi.h:171

Referenced by ListDevicesByType(), and RefreshDeviceList().

◆ GetNode()

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

Definition at line 1089 of file DeviceView.cpp.

1092 {
1093  TvItem->mask = TVIF_PARAM;
1094  if (TreeView_GetItem(m_hTreeView, TvItem))
1095  {
1096  return (CNode *)TvItem->lParam;
1097  }
1098  return nullptr;
1099 }
HWND m_hTreeView
Definition: DeviceView.h:19
Definition: Node.h:12
#define TVIF_PARAM
Definition: commctrl.h:3268
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3490

Referenced by GetSelectedNode().

◆ GetSelectedNode()

CNode * CDeviceView::GetSelectedNode ( )

Definition at line 320 of file DeviceView.cpp.

321 {
322  TV_ITEM TvItem;
323  TvItem.hItem = TreeView_GetSelection(m_hTreeView);
324  return GetNode(&TvItem);
325 }
HWND m_hTreeView
Definition: DeviceView.h:19
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3473
CNode * GetNode(_In_ LPTV_ITEMW TvItem)
#define TV_ITEM
Definition: commctrl.h:3300

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 772 of file DeviceView.cpp.

776 {
777  CONFIGRET cr;
778  cr = CM_Get_Sibling(DevInst,
779  PrevDevice,
780  0);
781  return (cr == CR_SUCCESS);
782 }
CONFIGRET WINAPI CM_Get_Sibling(_Out_ PDEVINST pdnDevInst, _In_ DEVINST dnDevInst, _In_ ULONG ulFlags)
Definition: cfgmgr.c:5525
#define CR_SUCCESS
Definition: cfgmgr32.h:842
RETURN_TYPE CONFIGRET
Definition: cfgmgr32.h:74

Referenced by RecurseChildDevices().

◆ 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,
69  m_hMainWnd,
72  NULL);
73  if (m_hTreeView)
74  {
75  // Set the image list against the treeview
78  TVSIL_NORMAL);
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 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define TVS_LINESATROOT
Definition: commctrl.h:3249
HINSTANCE g_hThisInstance
Definition: MainWindow.cpp:25
#define WS_CHILD
Definition: pedump.c:617
BOOL WINAPI SetupDiGetClassImageList(OUT PSP_CLASSIMAGELIST_DATA ClassImageListData)
Definition: devclass.c:322
static BOOLEAN bSuccess
Definition: drive.cpp:432
HWND m_hTreeView
Definition: DeviceView.h:19
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TVS_HASBUTTONS
Definition: commctrl.h:3247
HRESULT WINAPI SetWindowTheme(_In_ HWND hwnd, _In_ LPCWSTR pszSubAppName, _In_ LPCWSTR pszSubIdList)
Definition: uxthemesupp.c:69
virtual bool SetupNode()
Definition: RootNode.cpp:27
HWND m_hMainWnd
Definition: DeviceView.h:18
#define TreeView_SetImageList(hwnd, himl, iImage)
Definition: commctrl.h:3447
#define WC_TREEVIEW
Definition: commctrl.h:3245
static const WCHAR L[]
Definition: oid.c:1250
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 IDC_TREEVIEW
Definition: resource.h:13
#define WS_BORDER
Definition: pedump.c:625
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
#define NULL
Definition: types.h:112
#define TVS_SHOWSELALWAYS
Definition: commctrl.h:3252
#define TVS_HASLINES
Definition: commctrl.h:3248
#define TVSIL_NORMAL
Definition: commctrl.h:3443
struct _SP_CLASSIMAGELIST_DATA SP_CLASSIMAGELIST_DATA
#define WS_VISIBLE
Definition: pedump.c:620
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
SP_CLASSIMAGELIST_DATA m_ImageListData
Definition: DeviceView.h:29
CRootNode * m_RootNode
Definition: DeviceView.h:26

Referenced by CDeviceManager::OnCreate().

◆ InsertIntoTreeView()

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

Definition at line 785 of file DeviceView.cpp.

789 {
790  LPWSTR lpLabel;
791  lpLabel = Node->GetDisplayName();
792 
793  TV_ITEMW tvi;
794  TV_INSERTSTRUCT tvins;
795  ZeroMemory(&tvi, sizeof(tvi));
796  ZeroMemory(&tvins, sizeof(tvins));
797 
799  tvi.pszText = lpLabel;
800  tvi.cchTextMax = wcslen(lpLabel);
801  tvi.lParam = (LPARAM)Node;
802  tvi.iImage = Node->GetClassImage();
803  tvi.iSelectedImage = Node->GetClassImage();
804 
805  // try to cast it to a device node. This will only succeed if it's the correct type
806  CDeviceNode *DeviceNode = dynamic_cast<CDeviceNode *>(Node);
807  if (DeviceNode && DeviceNode->GetOverlayImage())
808  {
809  tvi.mask |= TVIF_STATE;
810  tvi.stateMask = TVIS_OVERLAYMASK;
811  tvi.state = INDEXTOOVERLAYMASK(DeviceNode->GetOverlayImage());
812  }
813 
814  tvins.item = tvi;
815  tvins.hParent = hParent;
816 
817  return TreeView_InsertItem(m_hTreeView, &tvins);
818 }
#define TV_ITEMW
Definition: commctrl.h:3297
#define ZeroMemory
Definition: winbase.h:1664
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3271
#define TreeView_InsertItem(hwnd, lpis)
Definition: commctrl.h:3412
HWND m_hTreeView
Definition: DeviceView.h:19
#define TVIS_OVERLAYMASK
Definition: commctrl.h:3287
LONG_PTR LPARAM
Definition: windef.h:208
Definition: Node.h:9
#define INDEXTOOVERLAYMASK(i)
Definition: commctrl.h:425
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
#define TVIF_TEXT
Definition: commctrl.h:3266
#define TVIF_IMAGE
Definition: commctrl.h:3267
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define TVIF_STATE
Definition: commctrl.h:3269
#define TVIF_PARAM
Definition: commctrl.h:3268
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define TV_INSERTSTRUCT
Definition: commctrl.h:3377
Definition: dlist.c:348

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

◆ ListDevicesByConnection()

bool CDeviceView::ListDevicesByConnection ( )
private

Definition at line 555 of file DeviceView.cpp.

556 {
557  // Walk the device tree and add all the devices
559 
560  // Expand the root item
562  m_hTreeRoot,
563  TVE_EXPAND);
564 
565  return true;
566 }
bool RecurseChildDevices(_In_ DEVINST ParentDevice, _In_ HTREEITEM hParentTreeItem)
Definition: DeviceView.cpp:569
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
HWND m_hTreeView
Definition: DeviceView.h:19
HTREEITEM m_hTreeRoot
Definition: DeviceView.h:23
#define TVE_EXPAND
Definition: commctrl.h:3423
DEVINST GetDeviceInst()
Definition: RootNode.h:15
#define TreeView_Expand(hwnd, hitem, code)
Definition: commctrl.h:3420
CRootNode * m_RootNode
Definition: DeviceView.h:26

◆ ListDevicesByType()

bool CDeviceView::ListDevicesByType ( )
private

Definition at line 423 of file DeviceView.cpp.

424 {
427  HDEVINFO hDevInfo;
428  HTREEITEM hTreeItem = NULL;
429  GUID ClassGuid;
430  INT ClassIndex;
431  BOOL bClassSuccess, bSuccess;
432 
433  ClassIndex = 0;
434  do
435  {
436  // Loop through all the device classes
437  bClassSuccess = GetNextClass(ClassIndex, &ClassGuid, &hDevInfo);
438  if (bClassSuccess)
439  {
440  bool AddedParent = false;
441  INT DeviceIndex = 0;
442  bool MoreItems = false;
443 
444  // Get the cached class node
445  ClassNode = GetClassNode(&ClassGuid);
446  if (ClassNode == nullptr)
447  {
448  ClassIndex++;
449  continue;
450  }
451 
452  // Check if this is a hidden class
453  if (IsEqualGUID(ClassGuid, GUID_DEVCLASS_LEGACYDRIVER) ||
454  IsEqualGUID(ClassGuid, GUID_DEVCLASS_VOLUME))
455  {
456  // Ignore this device if we aren't displaying hidden devices
457  if (m_ShowHidden == FALSE)
458  {
459  ClassIndex++;
460  continue;
461  }
462  }
463 
464  do
465  {
466  // Get a handle to all the devices in this class
470  bSuccess = SetupDiEnumDeviceInfo(hDevInfo,
471  DeviceIndex,
472  &DeviceInfoData);
474  MoreItems = false;
475 
476  if (bSuccess)
477  {
478  MoreItems = true;
479 
480  // Get the cached device node
482  if (DeviceNode == nullptr)
483  {
484  DeviceIndex++;
485  continue;
486  }
487 
488  // Check if this is a hidden device
489  if (DeviceNode->IsHidden())
490  {
491  // Ignore this device if we aren't displaying hidden devices
492  if (m_ShowHidden == FALSE)
493  {
494  DeviceIndex++;
495  continue;
496  }
497  }
498 
499  // We have a device, we need to add the parent if it hasn't yet been added
500  if (AddedParent == false)
501  {
502  // Insert the new class under the root item
503  hTreeItem = InsertIntoTreeView(m_hTreeRoot,
504  ClassNode);
505  AddedParent = true;
506  }
507 
508  // Add the device under the class item node
509  (void)InsertIntoTreeView(hTreeItem, DeviceNode);
510 
511  // Expand the class if it has a problem device
512  if (DeviceNode->HasProblem())
513  {
515  hTreeItem,
516  TVE_EXPAND);
517  }
518  }
519 
520  DeviceIndex++;
521 
522  } while (MoreItems);
523 
524  // If this class has devices, sort them alphabetically
525  if (AddedParent == true)
526  {
528  hTreeItem,
529  0);
530  }
531  }
532 
533  ClassIndex++;
534 
535  } while (bClassSuccess);
536 
537  // Sort the classes alphabetically
539  m_hTreeRoot,
540  0);
541 
542  // Expand the root item
544  m_hTreeRoot,
545  TVE_EXPAND);
546 
547  // Pre-select the root item
549  m_hTreeRoot);
550 
551  return 0;
552 }
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1783
#define TreeView_SortChildren(hwnd, hitem, recurse)
Definition: commctrl.h:3542
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define ZeroMemory
Definition: winbase.h:1664
int32_t INT
Definition: typedefs.h:58
static BOOLEAN bSuccess
Definition: drive.cpp:432
HWND m_hTreeView
Definition: DeviceView.h:19
CDeviceNode * GetDeviceNode(_In_ DEVINST Device)
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
Definition: Node.h:8
struct _SP_DEVINFO_DATA SP_DEVINFO_DATA
bool GetNextClass(_In_ ULONG ClassIndex, _Out_ LPGUID ClassGuid, _Out_ HDEVINFO *hDevInfo)
Definition: DeviceView.cpp:339
HTREEITEM m_hTreeRoot
Definition: DeviceView.h:23
_In_opt_ PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1528
HTREEITEM InsertIntoTreeView(_In_opt_ HTREEITEM hParent, _In_ CNode *Node)
Definition: DeviceView.cpp:785
#define TVE_EXPAND
Definition: commctrl.h:3423
Definition: Node.h:9
#define VOID
Definition: acefi.h:82
#define TreeView_SelectItem(hwnd, hitem)
Definition: commctrl.h:3481
#define NULL
Definition: types.h:112
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
CClassNode * GetClassNode(_In_ LPGUID ClassGuid)
bool m_ShowHidden
Definition: DeviceView.h:24
#define TreeView_Expand(hwnd, hitem, code)
Definition: commctrl.h:3420

◆ OnAction()

LRESULT CDeviceView::OnAction ( UINT  Action)

Definition at line 222 of file DeviceView.cpp.

225 {
226  switch (Action)
227  {
228  case IDM_PROPERTIES:
229  {
231  break;
232  }
233 
234  case IDM_SCAN_HARDWARE:
235  {
237  true,
238  true);
239  break;
240  }
241 
242  case IDM_ENABLE_DRV:
243  {
244  bool NeedsReboot;
245  if (EnableSelectedDevice(true, NeedsReboot) &&
246  NeedsReboot)
247  {
248  MessageBox(m_hMainWnd, L"Rebooting", L"Enable", MB_OK);
249  }
250  break;
251  }
252 
253  case IDM_DISABLE_DRV:
254  {
255  bool NeedsReboot;
256  EnableSelectedDevice(false, NeedsReboot);
257  break;
258  }
259 
260  case IDM_UPDATE_DRV:
261  {
262  bool NeedsReboot;
263  UpdateSelectedDevice(NeedsReboot);
264  break;
265  }
266 
267  case IDM_UNINSTALL_DRV:
268  {
270  break;
271  }
272 
273  case IDM_ADD_HARDWARE:
274  {
276  break;
277  }
278  }
279 
280  return 0;
281 }
#define IDM_UPDATE_DRV
Definition: resource.h:26
bool RunAddHardwareWizard()
Definition: DeviceView.cpp:735
VOID Refresh(_In_ ViewType Type, _In_ bool ScanForChanges, _In_ bool UpdateView)
Definition: DeviceView.cpp:195
bool UpdateSelectedDevice(_Out_ bool &NeedsReboot)
Definition: DeviceView.cpp:693
ViewType GetCurrentView()
Definition: DeviceView.h:74
#define IDM_UNINSTALL_DRV
Definition: resource.h:27
bool UninstallSelectedDevice()
Definition: DeviceView.cpp:712
bool EnableSelectedDevice(_In_ bool Enable, _Out_ bool &NeedsReboot)
Definition: DeviceView.cpp:665
HWND m_hMainWnd
Definition: DeviceView.h:18
VOID DisplayPropertySheet()
Definition: DeviceView.cpp:284
#define IDM_ADD_HARDWARE
Definition: resource.h:28
static const WCHAR L[]
Definition: oid.c:1250
#define IDM_PROPERTIES
Definition: resources.h:9
#define MessageBox
Definition: winuser.h:5798
#define IDM_SCAN_HARDWARE
Definition: resource.h:23
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:506
#define IDM_DISABLE_DRV
Definition: resource.h:25
#define MB_OK
Definition: winuser.h:784
#define IDM_ENABLE_DRV
Definition: resource.h:24

Referenced by CDeviceManager::OnCommand().

◆ OnContextMenu()

LRESULT CDeviceView::OnContextMenu ( _In_ LPARAM  lParam)

Definition at line 148 of file DeviceView.cpp.

151 {
153 
154  RECT rc;
156  hSelected,
157  &rc,
158  TRUE))
159  {
160  POINT pt;
161  if (GetCursorPos(&pt) &&
163  PtInRect(&rc, pt))
164  {
166  if (Node)
167  {
168  // Create the context menu
169  HMENU hContextMenu = CreatePopupMenu();
170 
171  // Add the actions for this node
172  BuildActionMenuForNode(hContextMenu, Node, false);
173 
174  INT xPos = GET_X_LPARAM(lParam);
175  INT yPos = GET_Y_LPARAM(lParam);
176 
177  // Display the menu
178  TrackPopupMenuEx(hContextMenu,
180  xPos,
181  yPos,
182  m_hMainWnd,
183  NULL);
184 
185  DestroyMenu(hContextMenu);
186  }
187  }
188  }
189 
190  return 0;
191 }
#define TreeView_GetItemRect(hwnd, hitem, prc, code)
Definition: commctrl.h:3429
#define TRUE
Definition: types.h:120
#define pt(x, y)
Definition: drawing.c:79
BOOL WINAPI TrackPopupMenuEx(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _In_ HWND, _In_opt_ LPTPMPARAMS)
#define GET_X_LPARAM(lp)
Definition: windowsx.h:274
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2635
int32_t INT
Definition: typedefs.h:58
#define TPM_RIGHTBUTTON
Definition: winuser.h:2356
HWND m_hTreeView
Definition: DeviceView.h:19
CNode * GetSelectedNode()
Definition: DeviceView.cpp:320
HWND m_hMainWnd
Definition: DeviceView.h:18
Definition: Node.h:12
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3473
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define NULL
Definition: types.h:112
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:275
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:846
BOOL WINAPI PtInRect(_In_ LPCRECT, _In_ POINT)
void BuildActionMenuForNode(_In_ HMENU OwnerMenu, _In_ CNode *Node, _In_ bool MainMenu)
Definition: DeviceView.cpp:821
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
LPARAM lParam
Definition: combotst.c:139
Definition: dlist.c:348

Referenced by CDeviceManager::OnContext().

◆ OnRightClick()

LRESULT CDeviceView::OnRightClick ( _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  hItem = TreeView_HitTest(m_hTreeView, &hitInfo);
139  if (hItem != NULL && (hitInfo.flags & (TVHT_ONITEM | TVHT_ONITEMICON)))
140  {
142  }
143 
144  return 0;
145 }
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2635
#define TVHT_ONITEMICON
Definition: commctrl.h:3525
HWND m_hTreeView
Definition: DeviceView.h:19
HTREEITEM hItem
Definition: treelist.h:37
#define TreeView_HitTest(hwnd, lpht)
Definition: commctrl.h:3513
#define TreeView_SelectItem(hwnd, hitem)
Definition: commctrl.h:3481
#define NULL
Definition: types.h:112
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)
#define TVHT_ONITEM
Definition: commctrl.h:3527

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,
122  SWP_NOZORDER);
123 
124  return 0;
125 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define SWP_NOZORDER
Definition: winuser.h:1233
HWND m_hTreeView
Definition: DeviceView.h:19
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:585
#define NULL
Definition: types.h:112
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
_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)

Referenced by CDeviceManager::OnSize().

◆ RecurseChildDevices()

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

Definition at line 569 of file DeviceView.cpp.

573 {
574  HTREEITEM hDevItem = NULL;
575  DEVINST Device;
576  bool HasProblem = false;
577  bool bSuccess;
578 
579  // Check if the parent has any child devices
581  return true;
582 
583  // Get the cached device node
585  DeviceNode = dynamic_cast<CDeviceNode *>(GetDeviceNode(Device));
586  if (DeviceNode == nullptr)
587  {
588  return false;
589  }
590 
591  // Don't show hidden devices if not requested
592  if ((m_ShowHidden == TRUE) || (!(DeviceNode->IsHidden())))
593  {
594  // Add this device to the tree under its parent
595  hDevItem = InsertIntoTreeView(hParentTreeItem,
596  DeviceNode);
597  if (hDevItem)
598  {
599  // Check if this child has any children itself
600  if (!RecurseChildDevices(Device, hDevItem))
601  HasProblem = true;
602  }
603 
604  if (DeviceNode->HasProblem())
605  {
606  HasProblem = true;
607  }
608  }
609 
610 
611  // Check for siblings
612  for (;;)
613  {
614  // Check if the parent device has anything at the same level
616  if (bSuccess == FALSE)
617  break;
618 
619  DeviceNode = dynamic_cast<CDeviceNode *>(GetDeviceNode(Device));
620  if (DeviceNode == nullptr)
621  {
622  continue;
623  }
624 
625  // Don't show hidden devices if not requested
626  if ((m_ShowHidden == TRUE) || (!(DeviceNode->IsHidden())))
627  {
628  if (DeviceNode->HasProblem())
629  {
630  HasProblem = true;
631  }
632 
633  // Add this device to the tree under its parent
634  hDevItem = InsertIntoTreeView(hParentTreeItem,
635  DeviceNode);
636  if (hDevItem)
637  {
638  // Check if this child has any children itself
639  if (!RecurseChildDevices(Device, hDevItem))
640  HasProblem = true;
641  }
642  }
643  }
644 
646  hParentTreeItem,
647  0);
648 
649  // Expand the class if it has a problem device
650  if (HasProblem == true)
651  {
653  hParentTreeItem,
654  TVE_EXPAND);
655  }
656 
657  // If there was a problem, expand the ancestors
658  if (HasProblem)
659  return false;
660 
661  return true;
662 }
bool RecurseChildDevices(_In_ DEVINST ParentDevice, _In_ HTREEITEM hParentTreeItem)
Definition: DeviceView.cpp:569
#define TreeView_SortChildren(hwnd, hitem, recurse)
Definition: commctrl.h:3542
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define TRUE
Definition: types.h:120
static BOOLEAN bSuccess
Definition: drive.cpp:432
_Must_inspect_result_ _In_ WDFDEVICE ParentDevice
Definition: wdfpdo.h:220
HWND m_hTreeView
Definition: DeviceView.h:19
CDeviceNode * GetDeviceNode(_In_ DEVINST Device)
#define FALSE
Definition: types.h:117
bool GetSiblingDevice(_In_ DEVINST PrevDevice, _Out_ PDEVINST DevInst)
Definition: DeviceView.cpp:772
HTREEITEM InsertIntoTreeView(_In_opt_ HTREEITEM hParent, _In_ CNode *Node)
Definition: DeviceView.cpp:785
#define TVE_EXPAND
Definition: commctrl.h:3423
Definition: Node.h:9
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
DWORD DEVINST
Definition: cfgmgr32.h:76
#define NULL
Definition: types.h:112
bool GetChildDevice(_In_ DEVINST ParentDevInst, _Out_ PDEVINST DevInst)
Definition: DeviceView.cpp:759
bool m_ShowHidden
Definition: DeviceView.h:24
#define TreeView_Expand(hwnd, hitem, code)
Definition: commctrl.h:3420

Referenced by ListDevicesByConnection().

◆ RecurseFindDevice()

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

Definition at line 918 of file DeviceView.cpp.

922 {
923  HTREEITEM FoundItem;
925  TVITEMW tvItem;
926  CNode *FoundNode;
927 
928  // Check if this node has any children
929  hItem = TreeView_GetChild(m_hTreeView, hParentItem);
930  if (hItem == NULL)
931  return NULL;
932 
933  // The lParam contains the node pointer data
934  tvItem.hItem = hItem;
935  tvItem.mask = TVIF_PARAM;
936  if (TreeView_GetItem(m_hTreeView, &tvItem) &&
937  tvItem.lParam != NULL)
938  {
939  // check for a matching node
940  FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
941  if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
942  (IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
943  {
944  // check if this is a class node, or a device with matching ID's
945  if ((FoundNode->GetNodeType() == ClassNode) ||
946  (wcscmp(FoundNode->GetDeviceId(), Node->GetDeviceId()) == 0))
947  {
948  return hItem;
949  }
950  }
951  }
952 
953  // This node may have its own children
954  FoundItem = RecurseFindDevice(hItem, Node);
955  if (FoundItem)
956  return FoundItem;
957 
958  // Loop all the siblings
959  for (;;)
960  {
961  // Get the next item at this level
963  if (hItem == NULL)
964  break;
965 
966  // The lParam contains the node pointer data
967  tvItem.hItem = hItem;
968  tvItem.mask = TVIF_PARAM;
969  if (TreeView_GetItem(m_hTreeView, &tvItem))
970  {
971  // check for a matching class
972  FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
973  if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
974  (IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
975  {
976  // check if this is a class node, or a device with matching ID's
977  if ((FoundNode->GetNodeType() == ClassNode) ||
978  (wcscmp(FoundNode->GetDeviceId(), Node->GetDeviceId()) == 0))
979  {
980  return hItem;
981  }
982  }
983  }
984 
985  // This node may have its own children
986  FoundItem = RecurseFindDevice(hItem, Node);
987  if (FoundItem)
988  return FoundItem;
989  }
990 
991  return hItem;
992 }
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3466
LPARAM lParam
Definition: commctrl.h:3325
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3467
UINT mask
Definition: commctrl.h:3316
HWND m_hTreeView
Definition: DeviceView.h:19
HTREEITEM RecurseFindDevice(_In_ HTREEITEM hParentItem, _In_ CNode *Node)
Definition: DeviceView.cpp:918
NodeType GetNodeType()
Definition: Node.h:36
HTREEITEM hItem
Definition: treelist.h:37
Definition: Node.h:12
Definition: Node.h:8
LPGUID GetClassGuid()
Definition: Node.h:37
LPWSTR GetDeviceId()
Definition: Node.h:40
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define NULL
Definition: types.h:112
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
HTREEITEM hItem
Definition: commctrl.h:3317
#define TVIF_PARAM
Definition: commctrl.h:3268
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3490
Definition: dlist.c:348

Referenced by SelectNode().

◆ Refresh()

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

Definition at line 195 of file DeviceView.cpp.

200 {
201  // Enum devices on a separate thread to keep the gui responsive
202 
203  m_ViewType = Type;
204 
207  ThreadData->This = this;
208  ThreadData->ScanForChanges = ScanForChanges;
209  ThreadData->UpdateView = UpdateView;
210 
211  HANDLE hThread;
213  0,
215  ThreadData,
216  0,
217  NULL);
219 }
#define CloseHandle
Definition: compat.h:598
_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)
ViewType m_ViewType
Definition: DeviceView.h:22
static void UpdateView(TreeListData *pData)
Definition: treelist.c:1636
Type
Definition: Type.h:6
PVOID HANDLE
Definition: typedefs.h:73
#define NULL
Definition: types.h:112
HANDLE hThread
Definition: wizard.c:28
static unsigned int __stdcall RefreshThread(void *Param)
Definition: DeviceView.cpp:363

Referenced by OnAction(), and CDeviceManager::RefreshView().

◆ RefreshDeviceList()

bool CDeviceView::RefreshDeviceList ( )
private

Definition at line 1120 of file DeviceView.cpp.

1121 {
1122  GUID ClassGuid;
1125  HDEVINFO hDevInfo;
1127  DWORD i;
1128  BOOL Success;
1129 
1130  ULONG ClassIndex = 0;
1131 
1132  EmptyLists();
1133 
1134  if (m_RootNode) delete m_RootNode;
1136  m_RootNode->SetupNode();
1137 
1138  // Loop through all the classes
1139  do
1140  {
1141  Success = GetNextClass(ClassIndex, &ClassGuid, &hDevInfo);
1142  if (Success)
1143  {
1144  // Create a new class node and add it to the list
1145  ClassNode = new CClassNode(&ClassGuid, &m_ImageListData);
1146  if (ClassNode->SetupNode())
1147  {
1148  m_ClassNodeList.AddTail(ClassNode);
1149  }
1150 
1151  SetupDiDestroyDeviceInfoList(hDevInfo);
1152  }
1153  ClassIndex++;
1154  } while (Success);
1155 
1156  // Get all the devices on the local machine
1157  hDevInfo = SetupDiGetClassDevsW(NULL,
1158  0,
1159  0,
1161  if (hDevInfo == INVALID_HANDLE_VALUE)
1162  {
1163  return false;
1164  }
1165 
1166  // loop though all the devices
1168  for (i = 0;; i++)
1169  {
1170  // Get the devinst for this device
1172  if (Success == FALSE)
1173  break;
1174 
1175  // create a new device node and add it to the list
1177  if (DeviceNode->SetupNode())
1178  {
1179  m_DeviceNodeList.AddTail(DeviceNode);
1180  }
1181  else
1182  {
1183  ATLASSERT(FALSE);
1184  }
1185  }
1186 
1187  SetupDiDestroyDeviceInfoList(hDevInfo);
1188 
1189  return TRUE;
1190 }
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1783
#define ATLASSERT(x)
Definition: CComVariant.cpp:10
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2288
#define TRUE
Definition: types.h:120
CAtlList< CClassNode * > m_ClassNodeList
Definition: DeviceView.h:27
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
CAtlList< CDeviceNode * > m_DeviceNodeList
Definition: DeviceView.h:28
void EmptyLists()
virtual bool SetupNode()
Definition: RootNode.cpp:27
Definition: Node.h:8
struct _SP_DEVINFO_DATA SP_DEVINFO_DATA
bool GetNextClass(_In_ ULONG ClassIndex, _Out_ LPGUID ClassGuid, _Out_ HDEVINFO *hDevInfo)
Definition: DeviceView.cpp:339
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2889
_In_opt_ PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1528
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: Node.h:9
#define DIGCF_ALLCLASSES
Definition: setupapi.h:172
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
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
SP_CLASSIMAGELIST_DATA m_ImageListData
Definition: DeviceView.h:29
CRootNode * m_RootNode
Definition: DeviceView.h:26
#define DIGCF_PRESENT
Definition: setupapi.h:171

◆ RefreshThread()

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

Definition at line 363 of file DeviceView.cpp.

364 {
366  CDeviceView *This = ThreadData->This;
367 
368  // Get a copy of the currently selected node
369  CNode *LastSelectedNode = This->GetSelectedNode();
370  if (LastSelectedNode == nullptr || (LastSelectedNode->GetNodeType() == RootNode))
371  {
372  LastSelectedNode = new CRootNode(*This->m_RootNode);
373  }
374  else if (LastSelectedNode->GetNodeType() == ClassNode)
375  {
376  LastSelectedNode = new CClassNode(*dynamic_cast<CClassNode *>(LastSelectedNode));
377  }
378  else if (LastSelectedNode->GetNodeType() == DeviceNode)
379  {
380  LastSelectedNode = new CDeviceNode(*dynamic_cast<CDeviceNode *>(LastSelectedNode));
381  }
382 
383  // Empty the treeview
384  This->EmptyDeviceView();
385 
386  // Re-add the root node to the tree
387  if (This->AddRootDevice() == false)
388  return 0;
389 
390  // Refresh the devices only if requested
391  if (ThreadData->ScanForChanges)
392  {
393  This->RefreshDeviceList();
394  }
395 
396  // display the type of view the user wants
397  switch (This->m_ViewType)
398  {
399  case DevicesByType:
400  (void)This->ListDevicesByType();
401  break;
402 
403  case DevicesByConnection:
404  (VOID)This->ListDevicesByConnection();
405  break;
406 
407  case ResourcesByType:
408  break;
409 
411  break;
412  }
413 
414  This->SelectNode(LastSelectedNode);
415 
416  delete ThreadData;
417 
418  return 0;
419 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
NodeType GetNodeType()
Definition: Node.h:36
Definition: Node.h:12
Definition: Node.h:8
Definition: Node.h:9
#define VOID
Definition: acefi.h:82
PCONFIGURATION_COMPONENT_DATA RootNode
Definition: macharm.c:19

Referenced by Refresh().

◆ RunAddHardwareWizard()

bool CDeviceView::RunAddHardwareWizard ( )
private

Definition at line 735 of file DeviceView.cpp.

736 {
737  PADDHARDWAREWIZARD pAddHardwareWizard;
739 
740  hModule = LoadLibraryW(L"hdwwiz.cpl");
741  if (hModule == NULL)
742  return false;
743 
744  pAddHardwareWizard = (PADDHARDWAREWIZARD)GetProcAddress(hModule,
745  "AddHardwareWizard");
746  if (pAddHardwareWizard == NULL)
747  {
749  return false;
750  }
751 
752  pAddHardwareWizard(m_hMainWnd, NULL);
753 
755  return true;
756 }
#define LoadLibraryW(x)
Definition: compat.h:606
HWND m_hMainWnd
Definition: DeviceView.h:18
#define FreeLibrary(x)
Definition: compat.h:607
VOID(WINAPI * PADDHARDWAREWIZARD)(HWND hwnd, LPWSTR lpName)
Definition: DeviceView.cpp:23
static const WCHAR L[]
Definition: oid.c:1250
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:612
HMODULE hModule
Definition: animate.c:44

Referenced by OnAction().

◆ SelDeviceIsInstalled()

bool CDeviceView::SelDeviceIsInstalled ( )

◆ SelDeviceIsStarted()

bool CDeviceView::SelDeviceIsStarted ( )

◆ SelectNode()

void CDeviceView::SelectNode ( _In_ CNode Node)
private

Definition at line 995 of file DeviceView.cpp.

998 {
1000 
1001  // Check if there are any items in the tree
1003  if (hRoot == NULL)
1004  return;
1005 
1006  // If we don't want to set select a node, just select root
1007  if (Node == nullptr || Node->GetNodeType() == RootNode)
1008  {
1010  return;
1011  }
1012 
1013  // Scan the tree looking for the node we want
1015  if (hItem)
1016  {
1018  }
1019  else
1020  {
1022  }
1023 }
HWND m_hTreeView
Definition: DeviceView.h:19
HTREEITEM RecurseFindDevice(_In_ HTREEITEM hParentItem, _In_ CNode *Node)
Definition: DeviceView.cpp:918
static HTREEITEM hRoot
Definition: treeview.c:381
HTREEITEM hItem
Definition: treelist.h:37
#define TreeView_GetRoot(hwnd)
Definition: commctrl.h:3475
#define TreeView_SelectItem(hwnd, hitem)
Definition: commctrl.h:3481
#define NULL
Definition: types.h:112
PCONFIGURATION_COMPONENT_DATA RootNode
Definition: macharm.c:19
Definition: dlist.c:348

◆ SetFocus()

void CDeviceView::SetFocus ( )

Definition at line 298 of file DeviceView.cpp.

299 {
301 }
VOID SetFocus()
Definition: DeviceView.cpp:298
HWND m_hTreeView
Definition: DeviceView.h:19

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

◆ SetHiddenDevices()

VOID CDeviceView::SetHiddenDevices ( _In_ bool  ShowHidden)
inline

Definition at line 69 of file DeviceView.h.

70  {
71  m_ShowHidden = ShowHidden;
72  }
bool m_ShowHidden
Definition: DeviceView.h:24

Referenced by CDeviceManager::OnCommand().

◆ Uninitialize()

bool CDeviceView::Uninitialize ( void  )

Definition at line 94 of file DeviceView.cpp.

95 {
97 
99  {
102  }
103 
104  return true;
105 }
#define ZeroMemory
Definition: winbase.h:1664
BOOL WINAPI SetupDiDestroyClassImageList(IN PSP_CLASSIMAGELIST_DATA ClassImageListData)
Definition: devclass.c:85
void EmptyDeviceView()
#define NULL
Definition: types.h:112
SP_CLASSIMAGELIST_DATA m_ImageListData
Definition: DeviceView.h:29

Referenced by CDeviceManager::OnDestroy().

◆ UninstallSelectedDevice()

bool CDeviceView::UninstallSelectedDevice ( )
private

Definition at line 712 of file DeviceView.cpp.

714 {
715  CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
716  if (Node == nullptr)
717  return false;
718 
720  if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_UNINSTALL))
721  {
723  str,
724  Node->GetDisplayName(),
726  {
727  return false;
728  }
729  }
730 
731  return Node->UninstallDevice();
732 }
#define IDYES
Definition: winuser.h:829
HINSTANCE g_hThisInstance
Definition: MainWindow.cpp:25
#define MB_ICONWARNING
Definition: winuser.h:780
#define MB_YESNO
Definition: winuser.h:811
const WCHAR * str
CNode * GetSelectedNode()
Definition: DeviceView.cpp:320
HWND m_hMainWnd
Definition: DeviceView.h:18
CStringT< wchar_t, StrTraitATL< wchar_t, ChTraitsCRT< wchar_t > > > CAtlStringW
Definition: atlstr.h:126
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
#define IDS_CONFIRM_UNINSTALL
Definition: resource.h:54
#define MB_DEFBUTTON2
Definition: winuser.h:793
Definition: dlist.c:348

Referenced by OnAction().

◆ UpdateSelectedDevice()

bool CDeviceView::UpdateSelectedDevice ( _Out_ bool NeedsReboot)
private

Definition at line 693 of file DeviceView.cpp.

696 {
697  CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
698  if (Node == nullptr)
699  return false;
700 
701  DWORD dwReboot;
702  if (InstallDevInst(m_hMainWnd, Node->GetDeviceId(), TRUE, &dwReboot))
703  {
704  NeedsReboot = false;
705  return true;
706  }
707 
708  return false;
709 }
#define TRUE
Definition: types.h:120
CNode * GetSelectedNode()
Definition: DeviceView.cpp:320
HWND m_hMainWnd
Definition: DeviceView.h:18
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI InstallDevInst(IN HWND hWndParent, IN LPCWSTR InstanceId, IN BOOL bUpdate, OUT LPDWORD lpReboot)
Definition: stubs.cpp:24
Definition: dlist.c:348

Referenced by OnAction().

Member Data Documentation

◆ m_ClassNodeList

CAtlList<CClassNode *> CDeviceView::m_ClassNodeList
private

Definition at line 27 of file DeviceView.h.

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

◆ m_DeviceNodeList

CAtlList<CDeviceNode *> CDeviceView::m_DeviceNodeList
private

Definition at line 28 of file DeviceView.h.

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

◆ m_hMainWnd

◆ m_hMenu

HMENU CDeviceView::m_hMenu
private

Definition at line 21 of file DeviceView.h.

◆ m_hPropertyDialog

HWND CDeviceView::m_hPropertyDialog
private

Definition at line 20 of file DeviceView.h.

◆ m_hTreeRoot

HTREEITEM CDeviceView::m_hTreeRoot
private

Definition at line 23 of file DeviceView.h.

Referenced by AddRootDevice(), ListDevicesByConnection(), and ListDevicesByType().

◆ m_hTreeView

◆ m_ImageListData

SP_CLASSIMAGELIST_DATA CDeviceView::m_ImageListData
private

Definition at line 29 of file DeviceView.h.

Referenced by CDeviceView(), Initialize(), RefreshDeviceList(), and Uninitialize().

◆ m_RootNode

CRootNode* CDeviceView::m_RootNode
private

Definition at line 26 of file DeviceView.h.

Referenced by AddRootDevice(), Initialize(), ListDevicesByConnection(), and RefreshDeviceList().

◆ m_ShowHidden

bool CDeviceView::m_ShowHidden
private

Definition at line 24 of file DeviceView.h.

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

◆ m_ViewType

ViewType CDeviceView::m_ViewType
private

Definition at line 22 of file DeviceView.h.

Referenced by GetCurrentView(), and Refresh().


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