Darkhydro
Darkhydro

Reputation: 2072

Why is IDXGISwapChain::SetFullscreenState failing to go fullscreen?

I am using DX11 in a game, and I want to be able to start the game in fullscreen reliably. This means I can go one of two routes: specifying fullscreen in the swap chain description, or starting windowed and immediately toggling to fullscreen. According to MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/bb174537(v=vs.85).aspx), you should create a swap chain in windowed mode and then toggle to fullscreen if you want to start in fullscreen mode, which is exactly what I am doing.

The problem is this: When I call IDXGISwapChain::SetFullscreenState(TRUE, NULL), the call fails and returns the DXGI_ERROR_NOT_CURRENTLY_AVAILABLE error code. According to MSDN, the reasons this might happen are as follows:

The first case is not true. I am running out of Visual Studio 2010 with the remote debugger, so unless the remote debugger uses Terminal Server, I'm fine on that one. The second case is not true either; no other windows are present on the desktop. The fourth case is also not true; again, no other windows are present on the desktop.

This leaves the third option. Keyboard focus. From what I gathered online, I created this code to get the keyboard focus before creating the DX11 graphics device.

HWND _returnValue = SetFocus(m_hWnd);
if(_returnValue == NULL) {
    PrintWarning("Unable to get keyboard focus on app activation.\n");
}

This call succeeds, but I still don't go fullscreen. I haven't been able to find an alternative to this, either. However, I do know that it is possible to steal keyboard focus reliably as I see Windows do it all the time and I've seen other apps do it.

So my question is this: How can I reliably go fullscreen? or How can I reliably get keyboard focus for my app?

EDIT: After reading this over a couple times I realized I missed some key information. The application always starts correctly in fullscreen if I use the .exe directly by double-clicking on it or by putting it in the startup menu on the target machine (although Windows firewall messages still make it fail to go fullscreen, but I don't need that to work). The only problem is when the app is started by another app or if it is started using the Visual Studio remote debugger.

Upvotes: 1

Views: 8547

Answers (2)

Michael Blackburn
Michael Blackburn

Reputation: 3229

For me, changing the screen display to "duplicate" rather than "extend" resolved this issue. I'm not sure what the root cause was, as I've had a full-screen ... uh ... "visualization application" open in Extended display mode while working in Visual Studio on a console application without issue until I ran into this situation. So try changing your display from "extend" to "duplicate."

Upvotes: 0

Booner
Booner

Reputation: 11

It seems likely that the debugger or some other application is stealing the focus, or the watchdog timer is getting you.

See the "Debugging in Full-Screen Mode" in the DXGI Overview in MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205075(v=vs.85).aspx#Debugging

In particular there is a registry key mentioned there which you might need to set.

Upvotes: 1

Related Questions