Microsoft DirectX 8.1 (Visual Basic)

DirectInputDevice8.SetCooperativeLevel

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)

Parts

object
Resolves to a DirectInputDevice8 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 Microsoft® 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 Microsoft® Windows® from displaying the cursor.

For keyboards, DISCL_NOWINKEY can be also be included with DISCL_NONEXCLUSIVE to disable the Windows logo key. the Windows logo key is always disabled when DISCL_EXCLUSIVE is specified. Note, however, that DISCL_NOWINKEY has no effect when the default action-mapping UI is displayed, and the Windows logo key operates normally as long as that UI is present.

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.

Applications that select the background exclusive mode cooperative level are not guaranteed to retain access to the device if another application requests exclusive access. When an background exclusive mode application loses access, calls to DirectInput device methods will fail and return DIERR_NOTACQUIRED. The application can regain access to the device by manually unacquiring the device and reaquiring it.

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 DirectInputDevice8.Acquire method.

See Also

Cooperative Levels