| 43 | } |
| 44 | |
| 45 | void CDeviceManagerView::Refresh() { |
| 46 | m_Tree.LockWindowUpdate(TRUE); |
| 47 | m_Tree.DeleteAllItems(); |
| 48 | |
| 49 | CImageList images = DeviceManager::GetClassImageList(); |
| 50 | m_ComputerIcon = images.AddIcon(ImageHelper::GetSystemIcon(SIID_DESKTOPPC)); |
| 51 | auto old = m_Tree.SetImageList(images, TVSIL_NORMAL); |
| 52 | if (old) |
| 53 | old.Destroy(); |
| 54 | |
| 55 | m_Devices = m_DevMgr->EnumDevices(); |
| 56 | std::unordered_map<GUID, HTREEITEM> devClasses; |
| 57 | devClasses.reserve(32); |
| 58 | m_DeviceClasses.clear(); |
| 59 | m_DeviceClasses.reserve(32); |
| 60 | |
| 61 | auto root = m_Tree.InsertItem(L"This PC", m_ComputerIcon, m_ComputerIcon, TVI_ROOT, TVI_LAST); |
| 62 | |
| 63 | for (auto& di : m_Devices) { |
| 64 | auto& guid = di.Data.ClassGuid; |
| 65 | if (guid == GUID_NULL) |
| 66 | continue; |
| 67 | auto it = devClasses.find(guid); |
| 68 | if (it == devClasses.end()) { |
| 69 | // add new device class |
| 70 | auto name = DeviceManager::GetDeviceClassDescription(&guid); |
| 71 | int image = DeviceManager::GetClassImageIndex(&guid); |
| 72 | auto hClass = m_Tree.InsertItem(name.c_str(), image, image, root, TVI_SORT); |
| 73 | m_DeviceClasses.insert({ hClass,guid }); |
| 74 | devClasses.insert({ guid,hClass }); |
| 75 | } |
| 76 | auto hClass = devClasses[guid]; |
| 77 | int image; |
| 78 | auto hIcon = m_DevMgr->GetDeviceIcon(di); |
| 79 | if (hIcon) |
| 80 | image = m_Tree.GetImageList().AddIcon(hIcon); |
| 81 | else |
| 82 | m_Tree.GetImageList().AddIcon(hIcon); |
| 83 | auto hItem = m_Tree.InsertItem(di.Description.c_str(), image, image, hClass, TVI_SORT); |
| 84 | m_Tree.SetItemData(hItem, (DWORD_PTR)&di); |
| 85 | } |
| 86 | |
| 87 | root.Expand(TVE_EXPAND); |
| 88 | |
| 89 | m_Tree.LockWindowUpdate(FALSE); |
| 90 | } |
| 91 | |
| 92 | void CDeviceManagerView::UpdateList() { |
| 93 | auto hSelected = m_Tree.GetSelectedItem(); |
nothing calls this directly
no test coverage detected