Sundar
Sundar

Reputation: 21

Hiding mouse cursor in multiscreen setup

I am trying to hide the mouse cursor using win32 API ShowCursor(FALSE), but on a multiscreen setup when the mouse gets to the other screen I don't get any mouse updates in windows.

Is there any way I can prevent this?

This is for a fullscreen video game and I don't seem to find any windows api that can do something like this.

Upvotes: 2

Views: 1697

Answers (1)

ThFabba
ThFabba

Reputation: 196

From what I understand, your problem is not in hiding the mouse cursor, but in constraining it to your window?

In that case, the ClipCursor function should do the job.

{
    RECT windowRect;
    GetWindowRect(hWnd, &windowRect);
    ClipCursor(&windowRect);
}

For a border-less full-screen window, it should be fine to do that once. You would need to repeat that step if your window's position or size ever changes or the window loses focus.

For game programming, there are likely better methods though, such as DirectInput, which provides an exclusive mouse handling mode (tutorials available) and does all that for you on a lower-level basis.

There are some discussions available about the different ways to handle this, for instance this one on the MSDN forums.

If, on the other hand, you want the cursor to be able to leave your window, and only hide it while it's over your window, you should handle the WM_SETCURSOR message and use SetCursor to hide the cursor.

case WM_SETCURSOR:
    SetCursor(NULL);
    return TRUE;

Upvotes: 1

Related Questions