Because Windows may force your application to unacquire the mouse when you have set the cooperative level to DISCL_FOREGROUND and the focus switches to another application or even to the menu in your own application, you should check for the DIERR_INPUTLOST return value from the IDirectInputDevice::GetDeviceData or IDirectInputDevice::GetDeviceState methods, and attempt to reacquire the mouse if necessary. (See Acquiring Devices.)
Note You should not attempt to reacquire the mouse on getting a DIERR_NOTACQUIRED error. If you do, you are likely to get caught in an infinite loop: acquisition will fail, you will get another DIERR_NOTACQUIRED error, and so on.