DirectX SDK

Step 2: Set Up Notifications

[C++]

This topic pertains only to application development in Visual Basic. See DirectInput C/C++ Tutorials.

[Visual Basic]

Rather than polling for mouse input in Sub Main, the ScrawlB sample application relies on DirectInput to notify it whenever a mouse event takes place. As part of initialization, the application gets an event handle and passes it to DirectInputDevice.SetEventNotification:

Dim EventHandle As Long
EventHandle = objDX.CreateEvent(frmCanvas)
Call objDIDev.SetEventNotification(EventHandle)
 

DirectInput will now notify any object that implements the DirectXEvent class. In the case of ScrawlB, the implementing object is the frmCanvas form, whose declarations section contains the following line:

Implements DirectXEvent
 

This line causes frmCanvas to inherit all the methods of the DirectXEvent class. As it happens, the only visible method of that class is DirectXEvent.DXCallback, and the inheriting class must implement this method. DirectInput will call this method whenever an input event is signaled.

The implementation of DXCallback is covered under Step 4: Retrieve Buffered Data from the Mouse.

Next: Step 3: Manage Exclusive Access to the Mouse