title: Why is IDXGISwapChain::SetFullscreenState failing to go fullscreen?
body: <p>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 (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174537%28v=vs.85%29.aspx" rel="nofollow" title="IDXGIFactory::CreateSwapChain">http://msdn.microsoft.com/en-us/library/windows/desktop/bb174537(v=vs.85).aspx</a>), 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. </p>
  
  <p>The problem is this: When I call <code>IDXGISwapChain::SetFullscreenState(TRUE, NULL)</code>, the call fails and returns the <code> DXGI_ERROR_NOT_CURRENTLY_AVAILABLE </code> error code. According to MSDN, the reasons this might happen are as follows: </p>
  
  <ul>
  <li>The application is running over Terminal Server.</li>
  <li>The output window is occluded.</li>
  <li>The output window does not have keyboard focus.</li>
  <li>Another application is already in full-screen mode.</li>
  </ul>
  
  <p>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. </p>
  
  <p>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.</p>
  
  <pre><code>HWND _returnValue = SetFocus(m_hWnd);
  if(_returnValue == NULL) {
      PrintWarning("Unable to get keyboard focus on app activation.\n");
  }</code></pre>
  
  <p>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. </p>
  
  <p>So my question is this: How can I reliably go fullscreen? or How can I reliably get keyboard focus for my app? </p>
  
  <p>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. </p>