Here, we want to show installed devices of our PC like what a Device Manager shows. In Device Manager, installed devices are shown in specific categories like: DVD/CD-ROM Drives or Floppy disk controllers. In my previous article, Enumerate Installed Devices Using Setup API, I show you how we can list all devices. In this article, installed devices are shown in a tree in their categories, like Device Manager.
For this purpose, I created a new class called
CDeviceTree that is inherited from
CTreeCtrl. Using of the new class is very simple.
How to Use
First of all, add DeviceTree.h and DeviceTree.cpp files to your project. Then in your dialog resource editor, add new Tree control (figure 2 shows it). Rename the control ID to your desired ID, for example
IDC_DEVICE_TREE. Run class wizard (Ctrl+W) and add new member variable with variable type
CDeviceTree does not appear in combo box, choose
CTreeCtrl, then in your dialog header file, rename
CDeviceTree). Name it as
Figure 2: Add new tree control to dialog resource
Figure 3: Add member variable with variable type CDeviceTree.
CDeviceTree does not appear in Variable type combo box, simply choose
CTreeCtrl, then rename it to
CDeviceTree in your dialog header file. For example:
Don't forget to include DeviceTree.h to your dialog header file. OK, now everything is ready to compile!
CDeviceTree class contains only one
public member function:
EnumDevices(). The function is responsible for enumerating all of the installed devices in their categories. The user must only use this function to see the tree of devices. The best way for this is
OnInitDialog() member function of main dialog. On the other hand:
SetIcon(m_hIcon, TRUE); SetIcon(m_hIcon, FALSE);
return TRUE; }
The class definition is as below:
class CDeviceTree : public CTreeCtrl
int EnumDevices(int index, TCHAR* DeviceClassName, TCHAR* DeviceName);
int EnumDeviceClasses(int index, TCHAR* DeviceClassName,
TCHAR* DeviceClassDesc, BOOL* DevicePresent, int* ClassImage);
#endif // _DEVICE_TREE_H_
As you see, the application shows devices like Device Manager does (Figure 4):
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.