Microsoft DirectX 8.1 (Visual Basic) |
Most Microsoft® DirectX® applications must enumerate available resources, usually during initialization. For example, an application that uses DirectX Graphics might need to find out what display modes are available, or an application using Microsoft DirectInput® might need to enumerate the available buttons and axes on a joystick.
In DirectX for Microsoft Visual Basic®, applications handle enumeration by obtaining the appropriate enumeration object. When an enumeration object is created, it builds a collection that exists as long as the object exists. Your application can then access that collection by using enumeration object's methods.
DirectX supports many enumeration objects, each tailored to a specific task. You normally obtain an enumeration object by calling a method. For example, the DirectX8 class contains two such methods. One of them, DirectX8.GetDSEnum returns a DirectSoundEnum8 enumeration object. This object enables you to enumerate Microsoft DirectSound® devices to obtain a GUID for a suitable device. You can then use this GUID to create a DirectSound8 object.
Other enumeration objects are obtained through various DirectX component objects. For example, you can call the DirectInput8.GetDIDevices method to obtain an enumeration object for input devices.
The following sample code illustrates how to enumerate all input devices attached to the system. The di variable is a DirectInput8 object. The first step is to obtain a DirectInputEnumDevices8 enumeration object.
Dim diEnum As DirectInputEnumDevices8 Set diEnum = di.GetDIDevices(0, DIEDFL_ATTACHEDONLY)
Next, use the DirectInputEnumDevices8 methods to iterate through the attached devices. Examine each device to determine if it has the particular capabilities you need. In the following example, the names of the devices are put in a list box:
Dim diDevice As DirectInputDeviceInstance Dim X As Integer For X = 1 To diEnum.GetCount Set diDevice = diEnum.GetItem(X) Call List1.AddItem(diDevice.ProductName) 'Examine device capabilities '... Next X
Note All collections created by DirectX enumerations are 1-based.