2015-06-16 21:13:28 +00:00
|
|
|
/*
|
2015-06-17 21:26:42 +00:00
|
|
|
* PROJECT: ReactOS Device Manager
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2015-10-15 17:21:37 +00:00
|
|
|
* FILE: dll/win32/devmgr/devmgmt/DeviceView.cpp
|
2015-06-17 21:26:42 +00:00
|
|
|
* PURPOSE: Implements the tree view which contains the devices
|
|
|
|
* COPYRIGHT: Copyright 2015 Ged Murphy <gedmurphy@reactos.org>
|
|
|
|
*/
|
|
|
|
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
|
2015-10-15 17:21:37 +00:00
|
|
|
#include "precomp.h"
|
2015-06-16 21:13:28 +00:00
|
|
|
#include "devmgmt.h"
|
|
|
|
#include "DeviceView.h"
|
|
|
|
|
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
// DATA ********************************************/
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
#define CLASS_NAME_LEN 256
|
|
|
|
#define CLASS_DESC_LEN 256
|
2015-06-17 21:26:42 +00:00
|
|
|
#define ROOT_NAME_SIZE MAX_COMPUTERNAME_LENGTH + 1
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2015-10-19 13:52:12 +00:00
|
|
|
|
|
|
|
typedef VOID(WINAPI *PADDHARDWAREWIZARD)(HWND hwnd, LPWSTR lpName);
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
struct RefreshThreadData
|
|
|
|
{
|
|
|
|
CDeviceView *This;
|
|
|
|
BOOL ScanForChanges;
|
2015-06-17 08:38:34 +00:00
|
|
|
BOOL UpdateView;
|
2015-06-16 21:13:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
// PUBLIC METHODS ************************************/
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
CDeviceView::CDeviceView(
|
|
|
|
HWND hMainWnd
|
|
|
|
) :
|
|
|
|
m_hMainWnd(hMainWnd),
|
|
|
|
m_hTreeView(NULL),
|
|
|
|
m_hPropertyDialog(NULL),
|
2015-06-17 08:15:08 +00:00
|
|
|
m_hMenu(NULL),
|
2015-06-16 21:13:28 +00:00
|
|
|
m_ViewType(DevicesByType),
|
2015-10-15 17:21:37 +00:00
|
|
|
m_ShowHidden(false),
|
2015-07-04 21:12:06 +00:00
|
|
|
m_RootNode(NULL)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
|
|
|
ZeroMemory(&m_ImageListData, sizeof(SP_CLASSIMAGELIST_DATA));
|
|
|
|
}
|
|
|
|
|
|
|
|
CDeviceView::~CDeviceView(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDeviceView::Initialize()
|
|
|
|
{
|
|
|
|
// Get the device image list
|
|
|
|
m_ImageListData.cbSize = sizeof(SP_CLASSIMAGELIST_DATA);
|
|
|
|
BOOL bSuccess = SetupDiGetClassImageList(&m_ImageListData);
|
2017-02-19 19:40:04 +00:00
|
|
|
if (bSuccess == FALSE)
|
|
|
|
return false;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
// Create the main treeview
|
|
|
|
m_hTreeView = CreateWindowExW(WS_EX_CLIENTEDGE,
|
|
|
|
WC_TREEVIEW,
|
|
|
|
NULL,
|
|
|
|
WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_HASLINES |
|
2015-06-17 08:15:08 +00:00
|
|
|
TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_LINESATROOT,
|
2015-06-16 21:13:28 +00:00
|
|
|
0, 0, 0, 0,
|
|
|
|
m_hMainWnd,
|
|
|
|
(HMENU)IDC_TREEVIEW,
|
2015-10-15 17:21:37 +00:00
|
|
|
g_hThisInstance,
|
2015-06-16 21:13:28 +00:00
|
|
|
NULL);
|
|
|
|
if (m_hTreeView)
|
|
|
|
{
|
|
|
|
// Set the image list against the treeview
|
|
|
|
(void)TreeView_SetImageList(m_hTreeView,
|
|
|
|
m_ImageListData.ImageList,
|
|
|
|
TVSIL_NORMAL);
|
|
|
|
|
|
|
|
// Give the treeview arrows instead of +/- boxes (on Win7)
|
|
|
|
SetWindowTheme(m_hTreeView, L"explorer", NULL);
|
2015-10-23 12:45:41 +00:00
|
|
|
|
|
|
|
// Create the root node
|
|
|
|
m_RootNode = new CRootNode(&m_ImageListData);
|
|
|
|
m_RootNode->SetupNode();
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2015-07-03 06:56:58 +00:00
|
|
|
|
2015-06-17 08:15:08 +00:00
|
|
|
|
2015-06-16 21:13:28 +00:00
|
|
|
return !!(m_hTreeView);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDeviceView::Uninitialize()
|
|
|
|
{
|
|
|
|
EmptyDeviceView();
|
|
|
|
|
|
|
|
if (m_ImageListData.ImageList != NULL)
|
|
|
|
{
|
|
|
|
SetupDiDestroyClassImageList(&m_ImageListData);
|
|
|
|
ZeroMemory(&m_ImageListData, sizeof(SP_CLASSIMAGELIST_DATA));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-17 08:15:08 +00:00
|
|
|
LRESULT
|
|
|
|
CDeviceView::OnSize(
|
2015-06-16 21:13:28 +00:00
|
|
|
_In_ int x,
|
|
|
|
_In_ int y,
|
|
|
|
_In_ int cx,
|
|
|
|
_In_ int cy
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Resize the treeview
|
|
|
|
SetWindowPos(m_hTreeView,
|
|
|
|
NULL,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
cx,
|
|
|
|
cy,
|
|
|
|
SWP_NOZORDER);
|
2015-06-17 08:15:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:52:41 +00:00
|
|
|
LRESULT
|
|
|
|
CDeviceView::OnDoubleClick(
|
|
|
|
_In_ LPNMHDR NmHdr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
TVHITTESTINFO hitInfo;
|
|
|
|
HTREEITEM hItem;
|
|
|
|
|
|
|
|
GetCursorPos(&hitInfo.pt);
|
|
|
|
ScreenToClient(m_hTreeView, &hitInfo.pt);
|
|
|
|
|
|
|
|
// Check if we are trying to double click an item
|
|
|
|
hItem = TreeView_HitTest(m_hTreeView, &hitInfo);
|
|
|
|
if (hItem != NULL && (hitInfo.flags & (TVHT_ONITEM | TVHT_ONITEMICON)))
|
|
|
|
{
|
|
|
|
DisplayPropertySheet();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-17 08:15:08 +00:00
|
|
|
LRESULT
|
|
|
|
CDeviceView::OnRightClick(
|
|
|
|
_In_ LPNMHDR NmHdr
|
|
|
|
)
|
|
|
|
{
|
2017-02-19 18:31:52 +00:00
|
|
|
TVHITTESTINFO hitInfo;
|
|
|
|
HTREEITEM hItem;
|
|
|
|
|
|
|
|
GetCursorPos(&hitInfo.pt);
|
|
|
|
ScreenToClient(m_hTreeView, &hitInfo.pt);
|
|
|
|
|
|
|
|
hItem = TreeView_HitTest(m_hTreeView, &hitInfo);
|
|
|
|
if (hItem != NULL && (hitInfo.flags & (TVHT_ONITEM | TVHT_ONITEMICON)))
|
2015-06-17 08:15:08 +00:00
|
|
|
{
|
2017-02-19 18:31:52 +00:00
|
|
|
TreeView_SelectItem(m_hTreeView, hItem);
|
2015-06-17 08:15:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT
|
|
|
|
CDeviceView::OnContextMenu(
|
|
|
|
_In_ LPARAM lParam
|
|
|
|
)
|
|
|
|
{
|
|
|
|
HTREEITEM hSelected = TreeView_GetSelection(m_hTreeView);
|
|
|
|
|
|
|
|
RECT rc;
|
|
|
|
if (TreeView_GetItemRect(m_hTreeView,
|
|
|
|
hSelected,
|
|
|
|
&rc,
|
|
|
|
TRUE))
|
|
|
|
{
|
|
|
|
POINT pt;
|
|
|
|
if (GetCursorPos(&pt) &&
|
|
|
|
ScreenToClient(m_hTreeView, &pt) &&
|
|
|
|
PtInRect(&rc, pt))
|
|
|
|
{
|
2015-07-03 06:56:58 +00:00
|
|
|
CNode *Node = GetSelectedNode();
|
|
|
|
if (Node)
|
|
|
|
{
|
2015-07-04 21:12:06 +00:00
|
|
|
// Create the context menu
|
|
|
|
HMENU hContextMenu = CreatePopupMenu();
|
|
|
|
|
|
|
|
// Add the actions for this node
|
2015-07-04 21:31:19 +00:00
|
|
|
BuildActionMenuForNode(hContextMenu, Node, false);
|
2015-07-04 21:12:06 +00:00
|
|
|
|
|
|
|
INT xPos = GET_X_LPARAM(lParam);
|
|
|
|
INT yPos = GET_Y_LPARAM(lParam);
|
|
|
|
|
|
|
|
// Display the menu
|
|
|
|
TrackPopupMenuEx(hContextMenu,
|
|
|
|
TPM_RIGHTBUTTON,
|
|
|
|
xPos,
|
|
|
|
yPos,
|
|
|
|
m_hMainWnd,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
DestroyMenu(hContextMenu);
|
2015-07-03 06:56:58 +00:00
|
|
|
}
|
2015-06-17 08:15:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 08:15:08 +00:00
|
|
|
|
2015-06-16 21:13:28 +00:00
|
|
|
void
|
2015-06-17 08:15:08 +00:00
|
|
|
CDeviceView::Refresh(
|
|
|
|
_In_ ViewType Type,
|
|
|
|
_In_ bool ScanForChanges,
|
2015-10-23 13:16:25 +00:00
|
|
|
_In_ bool UpdateView
|
2015-06-17 08:15:08 +00:00
|
|
|
)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
2016-11-12 21:53:33 +00:00
|
|
|
// Enum devices on a separate thread to keep the gui responsive
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
m_ViewType = Type;
|
|
|
|
|
|
|
|
RefreshThreadData *ThreadData;
|
2015-10-15 17:21:37 +00:00
|
|
|
ThreadData = new RefreshThreadData;
|
2015-06-16 21:13:28 +00:00
|
|
|
ThreadData->This = this;
|
|
|
|
ThreadData->ScanForChanges = ScanForChanges;
|
|
|
|
ThreadData->UpdateView = UpdateView;
|
2015-06-26 08:45:49 +00:00
|
|
|
|
2015-06-16 21:13:28 +00:00
|
|
|
HANDLE hThread;
|
|
|
|
hThread = (HANDLE)_beginthreadex(NULL,
|
|
|
|
0,
|
2015-10-15 17:21:37 +00:00
|
|
|
RefreshThread,
|
2015-06-16 21:13:28 +00:00
|
|
|
ThreadData,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (hThread) CloseHandle(hThread);
|
|
|
|
}
|
|
|
|
|
2015-07-05 08:49:54 +00:00
|
|
|
LRESULT
|
|
|
|
CDeviceView::OnAction(
|
|
|
|
_In_ UINT Action
|
|
|
|
)
|
|
|
|
{
|
|
|
|
switch (Action)
|
|
|
|
{
|
2019-08-03 19:52:00 +00:00
|
|
|
case IDM_PROPERTIES:
|
2015-07-05 08:49:54 +00:00
|
|
|
{
|
|
|
|
DisplayPropertySheet();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-03 19:52:00 +00:00
|
|
|
case IDM_SCAN_HARDWARE:
|
2015-07-05 08:49:54 +00:00
|
|
|
{
|
|
|
|
Refresh(GetCurrentView(),
|
|
|
|
true,
|
2015-10-23 13:16:25 +00:00
|
|
|
true);
|
2015-07-05 08:49:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-03 19:52:00 +00:00
|
|
|
case IDM_ENABLE_DRV:
|
2015-07-05 08:49:54 +00:00
|
|
|
{
|
|
|
|
bool NeedsReboot;
|
|
|
|
if (EnableSelectedDevice(true, NeedsReboot) &&
|
|
|
|
NeedsReboot)
|
|
|
|
{
|
|
|
|
MessageBox(m_hMainWnd, L"Rebooting", L"Enable", MB_OK);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-03 19:52:00 +00:00
|
|
|
case IDM_DISABLE_DRV:
|
2015-07-05 08:49:54 +00:00
|
|
|
{
|
|
|
|
bool NeedsReboot;
|
|
|
|
EnableSelectedDevice(false, NeedsReboot);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-03 19:52:00 +00:00
|
|
|
case IDM_UPDATE_DRV:
|
2015-07-05 08:49:54 +00:00
|
|
|
{
|
2015-10-19 08:45:48 +00:00
|
|
|
bool NeedsReboot;
|
|
|
|
UpdateSelectedDevice(NeedsReboot);
|
2015-07-05 08:49:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-03 19:52:00 +00:00
|
|
|
case IDM_UNINSTALL_DRV:
|
2015-07-05 08:49:54 +00:00
|
|
|
{
|
|
|
|
UninstallSelectedDevice();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-03 19:52:00 +00:00
|
|
|
case IDM_ADD_HARDWARE:
|
2015-07-05 08:49:54 +00:00
|
|
|
{
|
2015-10-19 13:52:12 +00:00
|
|
|
RunAddHardwareWizard();
|
2015-07-05 08:49:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-16 21:13:28 +00:00
|
|
|
void
|
|
|
|
CDeviceView::DisplayPropertySheet()
|
|
|
|
{
|
|
|
|
CNode *Node = GetSelectedNode();
|
|
|
|
if (Node && Node->HasProperties())
|
|
|
|
{
|
|
|
|
DevicePropertiesExW(m_hTreeView,
|
|
|
|
NULL,
|
|
|
|
Node->GetDeviceId(),
|
|
|
|
1,//DPF_EXTENDED,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CDeviceView::SetFocus()
|
|
|
|
{
|
2016-01-09 22:22:17 +00:00
|
|
|
::SetFocus(m_hTreeView);
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2015-07-04 21:12:06 +00:00
|
|
|
bool
|
|
|
|
CDeviceView::CreateActionMenu(
|
|
|
|
_In_ HMENU OwnerMenu,
|
|
|
|
_In_ bool MainMenu
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CNode *Node = GetSelectedNode();
|
|
|
|
if (Node)
|
|
|
|
{
|
2015-07-04 21:31:19 +00:00
|
|
|
BuildActionMenuForNode(OwnerMenu, Node, MainMenu);
|
2015-07-04 21:12:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-05 08:49:54 +00:00
|
|
|
CNode*
|
|
|
|
CDeviceView::GetSelectedNode()
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
2015-07-05 08:49:54 +00:00
|
|
|
TV_ITEM TvItem;
|
|
|
|
TvItem.hItem = TreeView_GetSelection(m_hTreeView);
|
|
|
|
return GetNode(&TvItem);
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-25 18:59:23 +00:00
|
|
|
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
// PRIVATE METHODS *******************************************/
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
CDeviceView::AddRootDevice()
|
|
|
|
{
|
2015-07-04 21:12:06 +00:00
|
|
|
m_hTreeRoot = InsertIntoTreeView(NULL, m_RootNode);
|
2015-06-16 21:13:28 +00:00
|
|
|
return (m_hTreeRoot != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-06-18 13:08:11 +00:00
|
|
|
CDeviceView::GetNextClass(
|
|
|
|
_In_ ULONG ClassIndex,
|
|
|
|
_Out_ LPGUID ClassGuid,
|
|
|
|
_Out_ HDEVINFO *hDevInfo
|
|
|
|
)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
|
|
|
CONFIGRET cr;
|
|
|
|
|
|
|
|
// Get the next class in the list
|
|
|
|
cr = CM_Enumerate_Classes(ClassIndex,
|
|
|
|
ClassGuid,
|
|
|
|
0);
|
2017-02-19 19:40:04 +00:00
|
|
|
if (cr != CR_SUCCESS)
|
|
|
|
return false;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2021-04-16 21:45:08 +00:00
|
|
|
// We only want the devices for this class
|
|
|
|
*hDevInfo = SetupDiGetClassDevsW(ClassGuid,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
DIGCF_PRESENT);
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
return (hDevInfo != INVALID_HANDLE_VALUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int __stdcall CDeviceView::RefreshThread(void *Param)
|
|
|
|
{
|
|
|
|
RefreshThreadData *ThreadData = (RefreshThreadData *)Param;
|
|
|
|
CDeviceView *This = ThreadData->This;
|
|
|
|
|
2015-10-23 12:45:41 +00:00
|
|
|
// Get a copy of the currently selected node
|
|
|
|
CNode *LastSelectedNode = This->GetSelectedNode();
|
|
|
|
if (LastSelectedNode == nullptr || (LastSelectedNode->GetNodeType() == RootNode))
|
|
|
|
{
|
|
|
|
LastSelectedNode = new CRootNode(*This->m_RootNode);
|
|
|
|
}
|
|
|
|
else if (LastSelectedNode->GetNodeType() == ClassNode)
|
|
|
|
{
|
|
|
|
LastSelectedNode = new CClassNode(*dynamic_cast<CClassNode *>(LastSelectedNode));
|
|
|
|
}
|
|
|
|
else if (LastSelectedNode->GetNodeType() == DeviceNode)
|
|
|
|
{
|
|
|
|
LastSelectedNode = new CDeviceNode(*dynamic_cast<CDeviceNode *>(LastSelectedNode));
|
|
|
|
}
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
// Empty the treeview
|
|
|
|
This->EmptyDeviceView();
|
|
|
|
|
2015-10-23 12:45:41 +00:00
|
|
|
// Re-add the root node to the tree
|
|
|
|
if (This->AddRootDevice() == false)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Refresh the devices only if requested
|
2015-06-16 21:13:28 +00:00
|
|
|
if (ThreadData->ScanForChanges)
|
|
|
|
{
|
|
|
|
This->RefreshDeviceList();
|
|
|
|
}
|
|
|
|
|
|
|
|
// display the type of view the user wants
|
|
|
|
switch (This->m_ViewType)
|
|
|
|
{
|
|
|
|
case DevicesByType:
|
|
|
|
(void)This->ListDevicesByType();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DevicesByConnection:
|
|
|
|
(VOID)This->ListDevicesByConnection();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ResourcesByType:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ResourcesByConnection:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-23 12:45:41 +00:00
|
|
|
This->SelectNode(LastSelectedNode);
|
2015-06-26 08:45:49 +00:00
|
|
|
|
2015-06-16 21:13:28 +00:00
|
|
|
delete ThreadData;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDeviceView::ListDevicesByType()
|
|
|
|
{
|
2015-06-17 21:26:42 +00:00
|
|
|
CClassNode *ClassNode;
|
|
|
|
CDeviceNode *DeviceNode;
|
2015-06-16 21:13:28 +00:00
|
|
|
HDEVINFO hDevInfo;
|
|
|
|
HTREEITEM hTreeItem = NULL;
|
|
|
|
GUID ClassGuid;
|
|
|
|
INT ClassIndex;
|
|
|
|
BOOL bClassSuccess, bSuccess;
|
|
|
|
|
|
|
|
ClassIndex = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// Loop through all the device classes
|
|
|
|
bClassSuccess = GetNextClass(ClassIndex, &ClassGuid, &hDevInfo);
|
|
|
|
if (bClassSuccess)
|
|
|
|
{
|
|
|
|
bool AddedParent = false;
|
|
|
|
INT DeviceIndex = 0;
|
2015-07-07 11:05:25 +00:00
|
|
|
bool MoreItems = false;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
// Get the cached class node
|
|
|
|
ClassNode = GetClassNode(&ClassGuid);
|
2015-10-15 17:21:37 +00:00
|
|
|
if (ClassNode == nullptr)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
|
|
|
ClassIndex++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-10-26 08:40:14 +00:00
|
|
|
// Check if this is a hidden class
|
|
|
|
if (IsEqualGUID(ClassGuid, GUID_DEVCLASS_LEGACYDRIVER) ||
|
|
|
|
IsEqualGUID(ClassGuid, GUID_DEVCLASS_VOLUME))
|
|
|
|
{
|
|
|
|
// Ignore this device if we aren't displaying hidden devices
|
|
|
|
if (m_ShowHidden == FALSE)
|
|
|
|
{
|
|
|
|
ClassIndex++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 21:13:28 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
// Get a handle to all the devices in this class
|
|
|
|
SP_DEVINFO_DATA DeviceInfoData;
|
|
|
|
ZeroMemory(&DeviceInfoData, sizeof(SP_DEVINFO_DATA));
|
|
|
|
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
|
|
|
bSuccess = SetupDiEnumDeviceInfo(hDevInfo,
|
|
|
|
DeviceIndex,
|
|
|
|
&DeviceInfoData);
|
|
|
|
if (bSuccess == FALSE && GetLastError() == ERROR_NO_MORE_ITEMS)
|
2015-07-07 11:05:25 +00:00
|
|
|
MoreItems = false;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
if (bSuccess)
|
|
|
|
{
|
2015-07-07 11:05:25 +00:00
|
|
|
MoreItems = true;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
// Get the cached device node
|
|
|
|
DeviceNode = GetDeviceNode(DeviceInfoData.DevInst);
|
2015-10-15 17:21:37 +00:00
|
|
|
if (DeviceNode == nullptr)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
|
|
|
DeviceIndex++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if this is a hidden device
|
|
|
|
if (DeviceNode->IsHidden())
|
|
|
|
{
|
|
|
|
// Ignore this device if we aren't displaying hidden devices
|
|
|
|
if (m_ShowHidden == FALSE)
|
|
|
|
{
|
|
|
|
DeviceIndex++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have a device, we need to add the parent if it hasn't yet been added
|
|
|
|
if (AddedParent == false)
|
|
|
|
{
|
|
|
|
// Insert the new class under the root item
|
|
|
|
hTreeItem = InsertIntoTreeView(m_hTreeRoot,
|
|
|
|
ClassNode);
|
|
|
|
AddedParent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the device under the class item node
|
|
|
|
(void)InsertIntoTreeView(hTreeItem, DeviceNode);
|
|
|
|
|
|
|
|
// Expand the class if it has a problem device
|
|
|
|
if (DeviceNode->HasProblem())
|
|
|
|
{
|
|
|
|
(void)TreeView_Expand(m_hTreeView,
|
|
|
|
hTreeItem,
|
|
|
|
TVE_EXPAND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceIndex++;
|
|
|
|
|
|
|
|
} while (MoreItems);
|
|
|
|
|
|
|
|
// If this class has devices, sort them alphabetically
|
|
|
|
if (AddedParent == true)
|
|
|
|
{
|
|
|
|
(void)TreeView_SortChildren(m_hTreeView,
|
|
|
|
hTreeItem,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassIndex++;
|
|
|
|
|
|
|
|
} while (bClassSuccess);
|
|
|
|
|
|
|
|
// Sort the classes alphabetically
|
|
|
|
(void)TreeView_SortChildren(m_hTreeView,
|
|
|
|
m_hTreeRoot,
|
|
|
|
0);
|
|
|
|
|
|
|
|
// Expand the root item
|
|
|
|
(void)TreeView_Expand(m_hTreeView,
|
|
|
|
m_hTreeRoot,
|
|
|
|
TVE_EXPAND);
|
|
|
|
|
|
|
|
// Pre-select the root item
|
|
|
|
(VOID)TreeView_SelectItem(m_hTreeView,
|
|
|
|
m_hTreeRoot);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDeviceView::ListDevicesByConnection()
|
|
|
|
{
|
2021-09-13 01:33:14 +00:00
|
|
|
// Walk the device tree and add all the devices
|
2015-07-04 21:12:06 +00:00
|
|
|
(void)RecurseChildDevices(m_RootNode->GetDeviceInst(), m_hTreeRoot);
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2021-09-13 01:33:14 +00:00
|
|
|
// Expand the root item
|
2015-06-18 10:26:30 +00:00
|
|
|
(void)TreeView_Expand(m_hTreeView,
|
2015-06-16 21:13:28 +00:00
|
|
|
m_hTreeRoot,
|
|
|
|
TVE_EXPAND);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-18 10:26:30 +00:00
|
|
|
bool
|
2015-06-16 21:13:28 +00:00
|
|
|
CDeviceView::RecurseChildDevices(
|
|
|
|
_In_ DEVINST ParentDevice,
|
|
|
|
_In_ HTREEITEM hParentTreeItem
|
|
|
|
)
|
|
|
|
{
|
|
|
|
HTREEITEM hDevItem = NULL;
|
|
|
|
DEVINST Device;
|
2015-06-18 10:26:30 +00:00
|
|
|
bool HasProblem = false;
|
|
|
|
bool bSuccess;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2021-09-13 01:33:14 +00:00
|
|
|
// Check if the parent has any child devices
|
2015-06-16 21:13:28 +00:00
|
|
|
if (GetChildDevice(ParentDevice, &Device) == FALSE)
|
2015-06-18 10:26:30 +00:00
|
|
|
return true;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
// Get the cached device node
|
2015-06-17 21:26:42 +00:00
|
|
|
CDeviceNode *DeviceNode;
|
|
|
|
DeviceNode = dynamic_cast<CDeviceNode *>(GetDeviceNode(Device));
|
2015-06-26 08:45:49 +00:00
|
|
|
if (DeviceNode == nullptr)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
2015-06-18 10:26:30 +00:00
|
|
|
return false;
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 10:26:30 +00:00
|
|
|
// Don't show hidden devices if not requested
|
2015-06-16 21:13:28 +00:00
|
|
|
if ((m_ShowHidden == TRUE) || (!(DeviceNode->IsHidden())))
|
|
|
|
{
|
2021-09-13 01:33:14 +00:00
|
|
|
// Add this device to the tree under its parent
|
2015-06-16 21:13:28 +00:00
|
|
|
hDevItem = InsertIntoTreeView(hParentTreeItem,
|
|
|
|
DeviceNode);
|
|
|
|
if (hDevItem)
|
|
|
|
{
|
2021-09-13 01:33:14 +00:00
|
|
|
// Check if this child has any children itself
|
2015-06-18 10:26:30 +00:00
|
|
|
if (!RecurseChildDevices(Device, hDevItem))
|
|
|
|
HasProblem = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DeviceNode->HasProblem())
|
|
|
|
{
|
|
|
|
HasProblem = true;
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 10:26:30 +00:00
|
|
|
// Check for siblings
|
2015-06-16 21:13:28 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2021-09-13 01:33:14 +00:00
|
|
|
// Check if the parent device has anything at the same level
|
2015-06-16 21:13:28 +00:00
|
|
|
bSuccess = GetSiblingDevice(Device, &Device);
|
2017-02-19 19:40:04 +00:00
|
|
|
if (bSuccess == FALSE)
|
|
|
|
break;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
DeviceNode = dynamic_cast<CDeviceNode *>(GetDeviceNode(Device));
|
2015-06-26 08:45:49 +00:00
|
|
|
if (DeviceNode == nullptr)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
2020-04-05 16:29:32 +00:00
|
|
|
continue;
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 13:08:11 +00:00
|
|
|
// Don't show hidden devices if not requested
|
|
|
|
if ((m_ShowHidden == TRUE) || (!(DeviceNode->IsHidden())))
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
2015-06-18 13:08:11 +00:00
|
|
|
if (DeviceNode->HasProblem())
|
|
|
|
{
|
2015-06-18 10:26:30 +00:00
|
|
|
HasProblem = true;
|
2015-06-18 13:08:11 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 01:33:14 +00:00
|
|
|
// Add this device to the tree under its parent
|
2015-06-18 13:08:11 +00:00
|
|
|
hDevItem = InsertIntoTreeView(hParentTreeItem,
|
|
|
|
DeviceNode);
|
|
|
|
if (hDevItem)
|
|
|
|
{
|
2021-09-13 01:33:14 +00:00
|
|
|
// Check if this child has any children itself
|
2015-06-18 13:08:11 +00:00
|
|
|
if (!RecurseChildDevices(Device, hDevItem))
|
|
|
|
HasProblem = true;
|
|
|
|
}
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)TreeView_SortChildren(m_hTreeView,
|
|
|
|
hParentTreeItem,
|
|
|
|
0);
|
|
|
|
|
2015-06-18 10:26:30 +00:00
|
|
|
// Expand the class if it has a problem device
|
|
|
|
if (HasProblem == true)
|
|
|
|
{
|
|
|
|
(void)TreeView_Expand(m_hTreeView,
|
|
|
|
hParentTreeItem,
|
|
|
|
TVE_EXPAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there was a problem, expand the ancestors
|
2017-02-19 19:40:04 +00:00
|
|
|
if (HasProblem)
|
|
|
|
return false;
|
2015-06-18 10:26:30 +00:00
|
|
|
|
|
|
|
return true;
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2015-07-05 08:49:54 +00:00
|
|
|
bool
|
|
|
|
CDeviceView::EnableSelectedDevice(
|
|
|
|
_In_ bool Enable,
|
|
|
|
_Out_ bool &NeedsReboot
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
|
2017-02-19 19:40:04 +00:00
|
|
|
if (Node == nullptr)
|
|
|
|
return false;
|
2015-07-05 08:49:54 +00:00
|
|
|
|
|
|
|
if (Enable == false)
|
|
|
|
{
|
|
|
|
CAtlStringW str;
|
2015-10-15 17:21:37 +00:00
|
|
|
if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_DISABLE))
|
2015-07-05 08:49:54 +00:00
|
|
|
{
|
|
|
|
if (MessageBoxW(m_hMainWnd,
|
2017-02-19 19:40:04 +00:00
|
|
|
str,
|
|
|
|
Node->GetDisplayName(),
|
|
|
|
MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) != IDYES)
|
2015-07-05 08:49:54 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 17:21:30 +00:00
|
|
|
return Node->EnableDevice(Enable, NeedsReboot);
|
2015-07-05 08:49:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 08:45:48 +00:00
|
|
|
bool
|
|
|
|
CDeviceView::UpdateSelectedDevice(
|
|
|
|
_Out_ bool &NeedsReboot
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
|
2017-02-19 19:40:04 +00:00
|
|
|
if (Node == nullptr)
|
|
|
|
return false;
|
2015-10-19 08:45:48 +00:00
|
|
|
|
|
|
|
DWORD dwReboot;
|
|
|
|
if (InstallDevInst(m_hMainWnd, Node->GetDeviceId(), TRUE, &dwReboot))
|
|
|
|
{
|
|
|
|
NeedsReboot = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-05 08:49:54 +00:00
|
|
|
bool
|
|
|
|
CDeviceView::UninstallSelectedDevice(
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
|
2017-02-19 19:40:04 +00:00
|
|
|
if (Node == nullptr)
|
|
|
|
return false;
|
2015-07-05 08:49:54 +00:00
|
|
|
|
2015-10-19 08:45:48 +00:00
|
|
|
CAtlStringW str;
|
|
|
|
if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_UNINSTALL))
|
|
|
|
{
|
|
|
|
if (MessageBoxW(m_hMainWnd,
|
2017-02-19 19:40:04 +00:00
|
|
|
str,
|
|
|
|
Node->GetDisplayName(),
|
|
|
|
MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) != IDYES)
|
2015-10-19 08:45:48 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-05 08:49:54 +00:00
|
|
|
return Node->UninstallDevice();
|
|
|
|
}
|
|
|
|
|
2015-10-19 13:52:12 +00:00
|
|
|
bool
|
|
|
|
CDeviceView::RunAddHardwareWizard()
|
|
|
|
{
|
|
|
|
PADDHARDWAREWIZARD pAddHardwareWizard;
|
|
|
|
HMODULE hModule;
|
|
|
|
|
|
|
|
hModule = LoadLibraryW(L"hdwwiz.cpl");
|
2017-02-19 19:40:04 +00:00
|
|
|
if (hModule == NULL)
|
|
|
|
return false;
|
2015-10-19 13:52:12 +00:00
|
|
|
|
|
|
|
pAddHardwareWizard = (PADDHARDWAREWIZARD)GetProcAddress(hModule,
|
|
|
|
"AddHardwareWizard");
|
|
|
|
if (pAddHardwareWizard == NULL)
|
|
|
|
{
|
|
|
|
FreeLibrary(hModule);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pAddHardwareWizard(m_hMainWnd, NULL);
|
|
|
|
|
|
|
|
FreeLibrary(hModule);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-16 21:13:28 +00:00
|
|
|
bool
|
|
|
|
CDeviceView::GetChildDevice(
|
|
|
|
_In_ DEVINST ParentDevInst,
|
|
|
|
_Out_ PDEVINST DevInst
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CONFIGRET cr;
|
|
|
|
cr = CM_Get_Child(DevInst,
|
|
|
|
ParentDevInst,
|
|
|
|
0);
|
|
|
|
return (cr == CR_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDeviceView::GetSiblingDevice(
|
|
|
|
_In_ DEVINST PrevDevice,
|
|
|
|
_Out_ PDEVINST DevInst
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CONFIGRET cr;
|
|
|
|
cr = CM_Get_Sibling(DevInst,
|
|
|
|
PrevDevice,
|
|
|
|
0);
|
|
|
|
return (cr == CR_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTREEITEM
|
|
|
|
CDeviceView::InsertIntoTreeView(
|
2015-07-04 21:12:06 +00:00
|
|
|
_In_opt_ HTREEITEM hParent,
|
2015-06-16 21:13:28 +00:00
|
|
|
_In_ CNode *Node
|
|
|
|
)
|
|
|
|
{
|
|
|
|
LPWSTR lpLabel;
|
|
|
|
lpLabel = Node->GetDisplayName();
|
|
|
|
|
|
|
|
TV_ITEMW tvi;
|
|
|
|
TV_INSERTSTRUCT tvins;
|
|
|
|
ZeroMemory(&tvi, sizeof(tvi));
|
|
|
|
ZeroMemory(&tvins, sizeof(tvins));
|
|
|
|
|
|
|
|
tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
|
|
|
|
tvi.pszText = lpLabel;
|
|
|
|
tvi.cchTextMax = wcslen(lpLabel);
|
|
|
|
tvi.lParam = (LPARAM)Node;
|
|
|
|
tvi.iImage = Node->GetClassImage();
|
|
|
|
tvi.iSelectedImage = Node->GetClassImage();
|
|
|
|
|
2016-11-12 21:53:33 +00:00
|
|
|
// try to cast it to a device node. This will only succeed if it's the correct type
|
2015-06-17 21:26:42 +00:00
|
|
|
CDeviceNode *DeviceNode = dynamic_cast<CDeviceNode *>(Node);
|
|
|
|
if (DeviceNode && DeviceNode->GetOverlayImage())
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
|
|
|
tvi.mask |= TVIF_STATE;
|
|
|
|
tvi.stateMask = TVIS_OVERLAYMASK;
|
2015-06-17 21:26:42 +00:00
|
|
|
tvi.state = INDEXTOOVERLAYMASK(DeviceNode->GetOverlayImage());
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tvins.item = tvi;
|
|
|
|
tvins.hParent = hParent;
|
|
|
|
|
|
|
|
return TreeView_InsertItem(m_hTreeView, &tvins);
|
|
|
|
}
|
|
|
|
|
2015-07-03 06:56:58 +00:00
|
|
|
void
|
2015-07-04 21:12:06 +00:00
|
|
|
CDeviceView::BuildActionMenuForNode(
|
|
|
|
_In_ HMENU OwnerMenu,
|
2015-07-04 21:31:19 +00:00
|
|
|
_In_ CNode *Node,
|
|
|
|
_In_ bool MainMenu
|
2015-07-03 06:56:58 +00:00
|
|
|
)
|
|
|
|
{
|
2021-09-13 01:33:14 +00:00
|
|
|
// Create a separator structure
|
2016-11-12 21:53:33 +00:00
|
|
|
MENUITEMINFOW MenuSeparator = { 0 };
|
|
|
|
MenuSeparator.cbSize = sizeof(MENUITEMINFOW);
|
|
|
|
MenuSeparator.fType = MFT_SEPARATOR;
|
2015-07-03 06:56:58 +00:00
|
|
|
|
2021-09-13 01:33:14 +00:00
|
|
|
// Setup the
|
2015-07-03 06:56:58 +00:00
|
|
|
MENUITEMINFOW MenuItemInfo = { 0 };
|
|
|
|
MenuItemInfo.cbSize = sizeof(MENUITEMINFOW);
|
|
|
|
MenuItemInfo.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA | MIIM_SUBMENU;
|
|
|
|
MenuItemInfo.fType = MFT_STRING;
|
|
|
|
|
2015-07-04 13:40:17 +00:00
|
|
|
CAtlStringW String;
|
2015-07-03 06:56:58 +00:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
// Device nodes have extra data
|
|
|
|
if (Node->GetNodeType() == DeviceNode)
|
|
|
|
{
|
|
|
|
CDeviceNode *DeviceNode = dynamic_cast<CDeviceNode *>(Node);
|
|
|
|
|
|
|
|
if (DeviceNode->CanUpdate())
|
|
|
|
{
|
2015-10-15 17:21:37 +00:00
|
|
|
String.LoadStringW(g_hThisInstance, IDS_MENU_UPDATE);
|
2019-08-03 19:52:00 +00:00
|
|
|
MenuItemInfo.wID = IDM_UPDATE_DRV;
|
2015-07-04 13:40:17 +00:00
|
|
|
MenuItemInfo.dwTypeData = String.GetBuffer();
|
2015-07-04 21:12:06 +00:00
|
|
|
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
|
2015-07-03 06:56:58 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DeviceNode->IsDisabled())
|
|
|
|
{
|
2015-10-15 17:21:37 +00:00
|
|
|
String.LoadStringW(g_hThisInstance, IDS_MENU_ENABLE);
|
2019-08-03 19:52:00 +00:00
|
|
|
MenuItemInfo.wID = IDM_ENABLE_DRV;
|
2015-07-04 13:40:17 +00:00
|
|
|
MenuItemInfo.dwTypeData = String.GetBuffer();
|
2015-07-04 21:12:06 +00:00
|
|
|
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
|
2015-07-03 06:56:58 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DeviceNode->CanDisable() && !DeviceNode->IsDisabled())
|
|
|
|
{
|
2015-10-15 17:21:37 +00:00
|
|
|
String.LoadStringW(g_hThisInstance, IDS_MENU_DISABLE);
|
2019-08-03 19:52:00 +00:00
|
|
|
MenuItemInfo.wID = IDM_DISABLE_DRV;
|
2015-07-04 13:40:17 +00:00
|
|
|
MenuItemInfo.dwTypeData = String.GetBuffer();
|
2015-07-04 21:12:06 +00:00
|
|
|
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
|
2015-07-03 06:56:58 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DeviceNode->CanUninstall())
|
|
|
|
{
|
2015-10-15 17:21:37 +00:00
|
|
|
String.LoadStringW(g_hThisInstance, IDS_MENU_UNINSTALL);
|
2019-08-03 19:52:00 +00:00
|
|
|
MenuItemInfo.wID = IDM_UNINSTALL_DRV;
|
2015-07-04 13:40:17 +00:00
|
|
|
MenuItemInfo.dwTypeData = String.GetBuffer();
|
2015-07-04 21:12:06 +00:00
|
|
|
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
|
2015-07-03 06:56:58 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2016-11-12 21:53:33 +00:00
|
|
|
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuSeparator);
|
2015-07-03 06:56:58 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All nodes have the scan option
|
2015-10-15 17:21:37 +00:00
|
|
|
String.LoadStringW(g_hThisInstance, IDS_MENU_SCAN);
|
2019-08-03 19:52:00 +00:00
|
|
|
MenuItemInfo.wID = IDM_SCAN_HARDWARE;
|
2015-07-04 13:40:17 +00:00
|
|
|
MenuItemInfo.dwTypeData = String.GetBuffer();
|
2015-07-04 21:12:06 +00:00
|
|
|
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
|
2015-07-03 06:56:58 +00:00
|
|
|
i++;
|
|
|
|
|
2015-07-04 21:31:19 +00:00
|
|
|
if ((Node->GetNodeType() == RootNode) || (MainMenu == true))
|
|
|
|
{
|
2015-10-15 17:21:37 +00:00
|
|
|
String.LoadStringW(g_hThisInstance, IDS_MENU_ADD);
|
2019-08-03 19:52:00 +00:00
|
|
|
MenuItemInfo.wID = IDM_ADD_HARDWARE;
|
2015-07-04 21:31:19 +00:00
|
|
|
MenuItemInfo.dwTypeData = String.GetBuffer();
|
|
|
|
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2015-07-03 06:56:58 +00:00
|
|
|
if (Node->HasProperties())
|
|
|
|
{
|
2016-11-12 21:53:33 +00:00
|
|
|
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuSeparator);
|
2015-07-03 06:56:58 +00:00
|
|
|
i++;
|
|
|
|
|
2015-10-15 17:21:37 +00:00
|
|
|
String.LoadStringW(g_hThisInstance, IDS_MENU_PROPERTIES);
|
2019-08-03 19:52:00 +00:00
|
|
|
MenuItemInfo.wID = IDM_PROPERTIES;
|
2015-07-04 13:40:17 +00:00
|
|
|
MenuItemInfo.dwTypeData = String.GetBuffer();
|
2015-07-04 21:12:06 +00:00
|
|
|
InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo);
|
2015-07-03 06:56:58 +00:00
|
|
|
i++;
|
|
|
|
|
2015-07-04 21:12:06 +00:00
|
|
|
SetMenuDefaultItem(OwnerMenu, IDC_PROPERTIES, FALSE);
|
2015-07-03 06:56:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 08:45:49 +00:00
|
|
|
HTREEITEM
|
|
|
|
CDeviceView::RecurseFindDevice(
|
|
|
|
_In_ HTREEITEM hParentItem,
|
2015-10-23 12:45:41 +00:00
|
|
|
_In_ CNode *Node
|
2015-06-16 21:13:28 +00:00
|
|
|
)
|
|
|
|
{
|
2015-06-26 08:45:49 +00:00
|
|
|
HTREEITEM FoundItem;
|
2015-06-16 21:13:28 +00:00
|
|
|
HTREEITEM hItem;
|
|
|
|
TVITEMW tvItem;
|
2015-10-23 12:45:41 +00:00
|
|
|
CNode *FoundNode;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
// Check if this node has any children
|
|
|
|
hItem = TreeView_GetChild(m_hTreeView, hParentItem);
|
2017-02-19 19:40:04 +00:00
|
|
|
if (hItem == NULL)
|
|
|
|
return NULL;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
// The lParam contains the node pointer data
|
|
|
|
tvItem.hItem = hItem;
|
|
|
|
tvItem.mask = TVIF_PARAM;
|
|
|
|
if (TreeView_GetItem(m_hTreeView, &tvItem) &&
|
|
|
|
tvItem.lParam != NULL)
|
|
|
|
{
|
2015-10-23 12:45:41 +00:00
|
|
|
// check for a matching node
|
|
|
|
FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
|
|
|
|
if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
|
|
|
|
(IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
|
2015-06-26 08:45:49 +00:00
|
|
|
{
|
2015-10-23 12:45:41 +00:00
|
|
|
// check if this is a class node, or a device with matching ID's
|
|
|
|
if ((FoundNode->GetNodeType() == ClassNode) ||
|
|
|
|
(wcscmp(FoundNode->GetDeviceId(), Node->GetDeviceId()) == 0))
|
|
|
|
{
|
|
|
|
return hItem;
|
|
|
|
}
|
2015-06-26 08:45:49 +00:00
|
|
|
}
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This node may have its own children
|
2015-10-23 12:45:41 +00:00
|
|
|
FoundItem = RecurseFindDevice(hItem, Node);
|
2017-02-19 19:40:04 +00:00
|
|
|
if (FoundItem)
|
|
|
|
return FoundItem;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2015-07-03 06:56:58 +00:00
|
|
|
// Loop all the siblings
|
2015-06-16 21:13:28 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
// Get the next item at this level
|
|
|
|
hItem = TreeView_GetNextSibling(m_hTreeView, hItem);
|
2017-02-19 19:40:04 +00:00
|
|
|
if (hItem == NULL)
|
|
|
|
break;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
// The lParam contains the node pointer data
|
|
|
|
tvItem.hItem = hItem;
|
|
|
|
tvItem.mask = TVIF_PARAM;
|
|
|
|
if (TreeView_GetItem(m_hTreeView, &tvItem))
|
|
|
|
{
|
2015-10-23 12:45:41 +00:00
|
|
|
// check for a matching class
|
|
|
|
FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
|
|
|
|
if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
|
|
|
|
(IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
|
2015-06-26 08:45:49 +00:00
|
|
|
{
|
2015-10-23 12:45:41 +00:00
|
|
|
// check if this is a class node, or a device with matching ID's
|
|
|
|
if ((FoundNode->GetNodeType() == ClassNode) ||
|
|
|
|
(wcscmp(FoundNode->GetDeviceId(), Node->GetDeviceId()) == 0))
|
|
|
|
{
|
|
|
|
return hItem;
|
|
|
|
}
|
2015-06-26 08:45:49 +00:00
|
|
|
}
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 01:33:14 +00:00
|
|
|
// This node may have its own children
|
2015-10-23 12:45:41 +00:00
|
|
|
FoundItem = RecurseFindDevice(hItem, Node);
|
2017-02-19 19:40:04 +00:00
|
|
|
if (FoundItem)
|
|
|
|
return FoundItem;
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 08:45:49 +00:00
|
|
|
return hItem;
|
|
|
|
}
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
void
|
2015-06-26 08:45:49 +00:00
|
|
|
CDeviceView::SelectNode(
|
2015-10-23 12:45:41 +00:00
|
|
|
_In_ CNode *Node
|
2015-06-26 08:45:49 +00:00
|
|
|
)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
2015-06-26 08:45:49 +00:00
|
|
|
HTREEITEM hRoot, hItem;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
// Check if there are any items in the tree
|
2015-06-26 08:45:49 +00:00
|
|
|
hRoot = TreeView_GetRoot(m_hTreeView);
|
2017-02-19 19:40:04 +00:00
|
|
|
if (hRoot == NULL)
|
|
|
|
return;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2015-07-03 06:56:58 +00:00
|
|
|
// If we don't want to set select a node, just select root
|
2015-10-23 12:45:41 +00:00
|
|
|
if (Node == nullptr || Node->GetNodeType() == RootNode)
|
2015-06-26 08:45:49 +00:00
|
|
|
{
|
2015-07-03 06:56:58 +00:00
|
|
|
TreeView_SelectItem(m_hTreeView, hRoot);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan the tree looking for the node we want
|
2015-10-23 12:45:41 +00:00
|
|
|
hItem = RecurseFindDevice(hRoot, Node);
|
2015-07-03 06:56:58 +00:00
|
|
|
if (hItem)
|
|
|
|
{
|
|
|
|
TreeView_SelectItem(m_hTreeView, hItem);
|
2015-06-26 08:45:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TreeView_SelectItem(m_hTreeView, hRoot);
|
|
|
|
}
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-26 08:45:49 +00:00
|
|
|
void
|
|
|
|
CDeviceView::EmptyDeviceView()
|
|
|
|
{
|
|
|
|
(VOID)TreeView_DeleteAllItems(m_hTreeView);
|
|
|
|
}
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
CClassNode*
|
2015-06-18 13:08:11 +00:00
|
|
|
CDeviceView::GetClassNode(
|
|
|
|
_In_ LPGUID ClassGuid
|
|
|
|
)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
|
|
|
POSITION Pos;
|
2015-10-23 12:45:41 +00:00
|
|
|
CClassNode *Node = nullptr;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
Pos = m_ClassNodeList.GetHeadPosition();
|
2017-02-19 19:40:04 +00:00
|
|
|
if (Pos == NULL)
|
|
|
|
return nullptr;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Node = m_ClassNodeList.GetNext(Pos);
|
|
|
|
if (IsEqualGUID(*Node->GetClassGuid(), *ClassGuid))
|
|
|
|
{
|
2015-10-15 17:21:37 +00:00
|
|
|
ATLASSERT(Node->GetNodeType() == ClassNode);
|
2015-06-16 21:13:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-23 12:45:41 +00:00
|
|
|
Node = nullptr;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
} while (Pos != NULL);
|
|
|
|
|
|
|
|
return Node;
|
|
|
|
}
|
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
CDeviceNode*
|
2015-06-18 13:08:11 +00:00
|
|
|
CDeviceView::GetDeviceNode(
|
|
|
|
_In_ DEVINST Device
|
|
|
|
)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
|
|
|
POSITION Pos;
|
2015-10-23 12:45:41 +00:00
|
|
|
CDeviceNode *Node = nullptr;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
Pos = m_DeviceNodeList.GetHeadPosition();
|
2017-02-19 19:40:04 +00:00
|
|
|
if (Pos == NULL)
|
|
|
|
return nullptr;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Node = m_DeviceNodeList.GetNext(Pos);
|
|
|
|
if (Node->GetDeviceInst() == Device)
|
|
|
|
{
|
2015-10-15 17:21:37 +00:00
|
|
|
ATLASSERT(Node->GetNodeType() == DeviceNode);
|
2015-06-16 21:13:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-23 12:45:41 +00:00
|
|
|
Node = nullptr;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
|
|
|
} while (Pos != NULL);
|
|
|
|
|
|
|
|
return Node;
|
|
|
|
}
|
|
|
|
|
2015-06-18 13:08:11 +00:00
|
|
|
CNode* CDeviceView::GetNode(
|
|
|
|
_In_ LPTV_ITEMW TvItem
|
|
|
|
)
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
|
|
|
TvItem->mask = TVIF_PARAM;
|
|
|
|
if (TreeView_GetItem(m_hTreeView, TvItem))
|
|
|
|
{
|
|
|
|
return (CNode *)TvItem->lParam;
|
|
|
|
}
|
2015-10-23 12:45:41 +00:00
|
|
|
return nullptr;
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CDeviceView::EmptyLists()
|
|
|
|
{
|
2015-06-18 13:08:11 +00:00
|
|
|
CNode *Node;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2015-06-18 10:26:30 +00:00
|
|
|
while (!m_ClassNodeList.IsEmpty())
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
2015-06-18 13:08:11 +00:00
|
|
|
Node = m_ClassNodeList.RemoveTail();
|
|
|
|
delete Node;
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 10:26:30 +00:00
|
|
|
while (!m_DeviceNodeList.IsEmpty())
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
2015-06-18 13:08:11 +00:00
|
|
|
Node = m_DeviceNodeList.RemoveTail();
|
|
|
|
delete Node;
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDeviceView::RefreshDeviceList()
|
|
|
|
{
|
|
|
|
GUID ClassGuid;
|
2015-06-17 21:26:42 +00:00
|
|
|
CClassNode *ClassNode;
|
|
|
|
CDeviceNode *DeviceNode;
|
2015-06-16 21:13:28 +00:00
|
|
|
HDEVINFO hDevInfo;
|
|
|
|
SP_DEVINFO_DATA DeviceInfoData;
|
|
|
|
DWORD i;
|
|
|
|
BOOL Success;
|
|
|
|
|
|
|
|
ULONG ClassIndex = 0;
|
|
|
|
|
|
|
|
EmptyLists();
|
|
|
|
|
2015-07-04 21:12:06 +00:00
|
|
|
if (m_RootNode) delete m_RootNode;
|
|
|
|
m_RootNode = new CRootNode(&m_ImageListData);
|
|
|
|
m_RootNode->SetupNode();
|
2015-10-15 17:21:37 +00:00
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
// Loop through all the classes
|
2015-06-16 21:13:28 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Success = GetNextClass(ClassIndex, &ClassGuid, &hDevInfo);
|
|
|
|
if (Success)
|
|
|
|
{
|
2015-06-17 21:26:42 +00:00
|
|
|
// Create a new class node and add it to the list
|
|
|
|
ClassNode = new CClassNode(&ClassGuid, &m_ImageListData);
|
|
|
|
if (ClassNode->SetupNode())
|
2015-06-16 21:13:28 +00:00
|
|
|
{
|
2015-06-17 21:26:42 +00:00
|
|
|
m_ClassNodeList.AddTail(ClassNode);
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
2015-06-26 08:45:49 +00:00
|
|
|
|
|
|
|
SetupDiDestroyDeviceInfoList(hDevInfo);
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
ClassIndex++;
|
|
|
|
} while (Success);
|
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
// Get all the devices on the local machine
|
2015-06-16 21:13:28 +00:00
|
|
|
hDevInfo = SetupDiGetClassDevsW(NULL,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
DIGCF_PRESENT | DIGCF_ALLCLASSES);
|
|
|
|
if (hDevInfo == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
// loop though all the devices
|
2015-06-16 21:13:28 +00:00
|
|
|
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
|
|
|
for (i = 0;; i++)
|
|
|
|
{
|
2015-06-17 21:26:42 +00:00
|
|
|
// Get the devinst for this device
|
2015-06-16 21:13:28 +00:00
|
|
|
Success = SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);
|
2017-02-19 19:40:04 +00:00
|
|
|
if (Success == FALSE)
|
|
|
|
break;
|
2015-06-16 21:13:28 +00:00
|
|
|
|
2015-06-17 21:26:42 +00:00
|
|
|
// create a new device node and add it to the list
|
|
|
|
DeviceNode = new CDeviceNode(DeviceInfoData.DevInst, &m_ImageListData);
|
|
|
|
if (DeviceNode->SetupNode())
|
|
|
|
{
|
|
|
|
m_DeviceNodeList.AddTail(DeviceNode);
|
|
|
|
}
|
2015-10-15 17:21:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ATLASSERT(FALSE);
|
|
|
|
}
|
2015-06-16 21:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetupDiDestroyDeviceInfoList(hDevInfo);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|