Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 468021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:38:25+00:00 2026-05-12T23:38:25+00:00

I have lost many hours trying to grab exclusively the mouse in my application

  • 0

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?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:38:25+00:00Added an answer on May 12, 2026 at 11:38 pm

    Possibly it because of this
    http://doc.51windows.net/Directx9_SDK/?url=/directx9_sdk/input/ref/ifaces/idirectinputdevice9/setcooperativelevel.htm
    “”An application that acquires the mouse or keyboard device in exclusive mode should always unacquire the devices when it receives WM_ENTERSIZEMOVE and WM_ENTERMENULOOP messages.
    Otherwise, the user cannot manipulate the menu or move and resize the window.””

    May be its not totally answer
    But try also to check if may be you not unacquire mouse on some other messeges.
    For example on WM_LOSTFOCUS, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is deceptively simple, but I have lost several hours of study trying
I am writing a custom textfile-data parser (JSON-like) and I have lost many hours
Let's say I have a gwt application with many widgets and I've used them
I have many source/text file, say file.cpp or file.txt . Now, I want to
I have read many posts about this now but I do not still understand
Asp.net MVC2: I have many dropdownlists in my mvc application. At first, I started
I have a Java Swing application, that has many JTextFields and a datamodel. When
I have a problem with my application: my application has many forms and need
Over the past three weeks, I have lost at least 120 man hours because
Im facing a Problem my HDD died and I lost many application which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.