Platform SDK: DirectX |
This topic pertains only to applications written in Visual Basic.
Most DirectX applications have to perform enumerations of available resources, usually during the initialization stage. For example, an application that uses DirectDraw might need to find out what display modes are available, or an application using DirectInput might need to enumerate the available buttons and axes on a joystick.
In DirectX for Visual Basic, enumerations are handled automatically when the application obtains an enumeration object. When the enumeration object is created, it builds a collection. This collection exists as long as the object exists, and can be accessed by using methods of the enumeration object.
Some enumeration objects must be obtained from the DirectX7 object. For example, you enumerate DirectSound devices by calling the DirectX7.GetDSEnum method. Only after obtaining the GUID for a suitable device from the collection can you create the DirectSound object.
Other enumeration objects are obtained from DirectX component objects. Once you obtain a DirectInput object, for example, you can call the DirectInput.GetDIEnumDevices method to obtain an enumeration object for input devices.
The following sample code, where di is a DirectInput object, enumerates all input devices attached to the system:
Dim diEnum As DirectInputEnumDevices Set diEnum = di.GetDIEnumDevices(0, DIEDFL_ATTACHEDONLY)
The two methods of the DirectInputEnumDevices object can now be used to iterate through the attached devices to look for one with particular capabilities or to perform some other task. 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) Next X
Note that all collections created by DirectX enumerations are 1-based.