Question

I am working on a DX11 game, and I want to clip the cursor during fullscreen mode to the fullscreen window. I use this method


void MyClass::_SetupCursor( BOOL bFullscreen ) {
    // Clip cursor if requested
    if( bFullscreen ) {
        if(m_bShowCursorWhenFullscreen) {
            ShowCursor(m_bShowCursorWhenFullscreen);
        }
        if(m_bClipCursorWhenFullscreen) {
            // Confine cursor to full screen window
            RECT windowRect;
            GetWindowRect( m_hWnd, &windowRect );
            ClipCursor( &windowRect );
        }
    }
    else {
        ShowCursor( TRUE );
        ClipCursor( NULL );
    }
}

However, when I am in fullscreen mode with 2 monitors, I can still move the mouse over to the other monitor. With resolution set to 2048x1152 in fullscreen mode, I get the window rectangle as 1360x768, and that is what it gets clipped to. I confirm that it is clipped using GetClippedRect.

So I have two questions:

1) Why isn't the mouse getting clipped to the monitor my window is in?

2) Why is the window rectangle measured as 1360x768 when I know for a fact the monitor is 2048x1152, and I have the resolution set to 2048x1152?

Was it helpful?

Solution

It turns out that for ClipCursor to work, you must have all your DX11 buffers and your window size correct. I found this out by running my application in fullscreen first, without toggling into it, and ClipCursor worked just fine, even with multiple monitors. For more information on when ClipCursor will fail, check out my other question on stackoverflow: Why is D3D10SDKLayers.dll loaded during my DX11 game? .

ClipCursor will fail ever time the situations i describe in that question arise. Also, in response to my 2nd question, the window size is incorrect because of the situation I describe in the linked question.

OTHER TIPS

Unfortunately according to a comment on the documentation (by a user) it appears that this does not work for multimonitor setups. You may want to develop a method that will reposition the mouse when it goes off screen, turns off the rendring for it, then turn it back on when you move the cursor back to the window (to detect if the mouse moves off the window or not, there is windows messages for that).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top