DirectX SDK

DirectInputDevice.SetCooperativeLevel

The DirectInputDevice.SetCooperativeLevel method establishes the cooperative level for this instance of the device. The cooperative level determines how this instance of the device interacts with other instances of the device and the rest of the system.

object.SetCooperativeLevel(hwnd As Long, _
  flags As CONST_DISCLFLAGS)

Parameters

object
Object expression that resolves to a DirectInputDevice object.
hwnd
Window handle to be associated with the device. This parameter must be a valid top-level window handle that belongs to the process. The window associated with the device must not be destroyed while it is still active in a DirectInput device.
flags
Flags that describe the cooperative level associated with the device. The flags are constants of the CONST_DISCLFLAGS enumeration.

The following combinations of flags are valid:
Flags Meaning Valid for
DISCL_NONEXCLUSIVE Or DISCL_BACKGROUND Others can acquire device in exclusive or nonexclusive mode; your application has access to data at all times. All.
DISCL_NONEXCLUSIVE Or DISCL_FOREGROUND Others can acquire device in exclusive or nonexclusive mode; your application has access to data only when in the foreground. All.
DISCL_EXCLUSIVE Or DISCL_BACKGROUND Others can acquire device in nonexclusive mode; your application has access to data at all times. Joystick.
DISCL_EXCLUSIVE Or DISC_FOREGROUND Others can acquire device in nonexclusive mode; your application has access to data only when in the foreground. All. Valid for mouse but prevents Windows from displaying the cursor.

Error Codes

If the method fails, an error is raised and Err.Number may be one of the following error codes:

DIERR_INVALIDPARAM
DIERR_INVALIDHANDLE

Remarks

No two applications (or instances of the same application) can have a device acquired in exclusive mode at the same time. This is primarily a security feature; it prevents input intended for one application from going to another that may be running concurrently.

If the system mouse is acquired in exclusive mode, then the pointer will be removed from the screen until the device is unacquired.

Applications must call this method before acquiring the device by using the DirectInputDevice.Acquire method.

See Also

Cooperative Levels