示例#1
0
unsigned int __stdcall CDeviceView::RefreshThread(void *Param)
{
    RefreshThreadData *ThreadData = (RefreshThreadData *)Param;
    CDeviceView *This = ThreadData->This;

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

    // Empty the treeview
    This->EmptyDeviceView();

    // Re-add the root node to the tree
    if (This->AddRootDevice() == false)
        return 0;

    // Refresh the devices only if requested
    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;
    }


    This->SelectNode(LastSelectedNode);

    delete ThreadData;

    return 0;
}
示例#2
0
HTREEITEM
CDeviceView::RecurseFindDevice(
    _In_ HTREEITEM hParentItem,
    _In_ CNode *Node
    )
{
    HTREEITEM FoundItem;
    HTREEITEM hItem;
    TVITEMW tvItem;
    CNode *FoundNode;

    // Check if this node has any children
    hItem = TreeView_GetChild(m_hTreeView, hParentItem);
    if (hItem == NULL) return NULL;

    // The lParam contains the node pointer data
    tvItem.hItem = hItem;
    tvItem.mask = TVIF_PARAM;
    if (TreeView_GetItem(m_hTreeView, &tvItem) &&
        tvItem.lParam != NULL)
    {
        // check for a matching node
        FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
        if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
            (IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
        {
            // 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;
            }
        }
    }

    // This node may have its own children
    FoundItem = RecurseFindDevice(hItem, Node);
    if (FoundItem) return FoundItem;

    // Loop all the siblings
    for (;;)
    {
        // Get the next item at this level
        hItem = TreeView_GetNextSibling(m_hTreeView, hItem);
        if (hItem == NULL) break;

        // The lParam contains the node pointer data
        tvItem.hItem = hItem;
        tvItem.mask = TVIF_PARAM;
        if (TreeView_GetItem(m_hTreeView, &tvItem))
        {
            // check for a matching class
            FoundNode = reinterpret_cast<CNode *>(tvItem.lParam);
            if ((FoundNode->GetNodeType() == Node->GetNodeType()) &&
                (IsEqualGUID(*FoundNode->GetClassGuid(), *Node->GetClassGuid())))
            {
                // 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;
                }
            }
        }

        // This node may have its own children 
        FoundItem = RecurseFindDevice(hItem, Node);
        if (FoundItem) return FoundItem;
    }

    return hItem;
}