Hello. I have lost many hours trying to grab exclusively the mouse in my application and re-releasing it.
Right now, I am grabbing it correctly : the mouse cursor disappears from screen and I can read its properties fine.
However, I can't release it correctly! The mouse cursor reappears on screen but no other application is receiving any mouse clicks any more; except mine.
Here is the problematic code :
IDirectInputDevice8* mMouse;
void Win32Mouse::grab(bool grab)
{
if (mGrabMouse == grab)
return;
mMouse->Unacquire();
if (grab)
{
// grab = true; seems to work fine
coopSetting &= ~DISCL_BACKGROUND;
coopSetting &= ~DISCL_NONEXCLUSIVE;
coopSetting |= DISCL_FOREGROUND | DISCL_EXCLUSIVE;
}
else
{
// grab = false; this surely isn't working as it should
coopSetting &= ~DISCL_FOREGROUND;
coopSetting &= ~DISCL_EXCLUSIVE;
coopSetting |= DISCL_BACKGROUND | DISCL_NONEXCLUSIVE;
}
if( FAILED(mMouse->SetCooperativeLevel(mHwnd, coopSetting)) ) {
std::cout << "Failed to set coop level\n";
}
HRESULT hr = mMouse->Acquire();
if (FAILED(hr) && hr != DIERR_OTHERAPPHASPRIO) {
std::cout << "Failed to aquire mouse!\n";
}
mGrabMouse = grab;
}
Could the problem be that I have Windows7?!
Many thanks in advance,
Bill Kotsias