Platform SDK: DirectX

Tutorial 2: Using the Mouse

[Visual Basic]

The information in this topic pertains only to applications written in C++. See DirectInput Visual Basic Tutorials.

[C++]

This tutorial guides you through the process of setting up a mouse device and retrieving buffered input data. The examples are based on the Scrawl sample.

To prepare for mouse input, you first create an instance of a DirectInput object. Then you use the IDirectInput7::CreateDeviceEx method to create an instance of an IDirectInputDevice7 interface. The IDirectInputDevice7 interface methods are used to manipulate the device, set its behavior, and retrieve data.

The preliminary step of setting up the DirectInput system and the final step of closing it down are the same for any application and are covered in Tutorial 1: Using the Keyboard.

This tutorial breaks down the required tasks into the following steps:

Note  When an application acquires the mouse at the exclusive cooperative level, Windows does not show a mouse pointer on the screen. For this, your application needs a simple sprite engine. The Scrawl sample application uses the Win32 function DrawIcon to display a crosshair cursor.