title: Win32: Add black borders to fullscreen window
body: <p>I am trying to preserve content aspect ratio in fullscreen mode in Windows. I'd like to hide the rest of the desktop behind black borders if the display aspect ratio differs from the content aspect ratio. Is it possible to create fullscreen window with centered content and black borders with Win32 api?</p>
  
  <p>In OS X this can be achieved quite easily with the following code:</p>
  
  <pre><code>CGSize ar;
  ar.width = 800;
  ar.height = 600;
  [self.window setContentAspectRatio:ar];
  [self.window center];
  [self.window toggleFullScreen:nil];
  </code></pre>
  
  <p>If I run the above code in 16:9 display, my app goes to fullscreen mode, the content is centered (since it is 4:3) and I have black borders on both sides of the screen.</p>
  
  <p>I have tried to implement the same functionality in Windows but I begin to wonder if it is even possible. My current fullscreen code maintains the aspect ratio and
  centers the content, but shows the desktop on the both sides of the window if the <code>fullscreenWidth</code> and <code>fullscreenHeight</code> are not equal to <code>displayWidth</code> and <code>displayHeight</code>:</p>
  
  <pre><code>bool enterFullscreen(int fullscreenWidth, int fullscreenHeight)
  {
      DEVMODE fullscreenSettings;
      bool isChangeSuccessful;
  
      int displayWidth = GetDeviceCaps(m_hDC, HORZRES);
      int displayHeight = GetDeviceCaps(m_hDC, VERTRES);
  
      int colourBits = GetDeviceCaps(m_hDC, BITSPIXEL);
      int refreshRate = GetDeviceCaps(m_hDC, VREFRESH);
  
      EnumDisplaySettings(NULL, 0, &amp;fullscreenSettings);
      fullscreenSettings.dmPelsWidth = fullscreenWidth;
      fullscreenSettings.dmPelsHeight = fullscreenHeight;
      fullscreenSettings.dmBitsPerPel = colourBits;
      fullscreenSettings.dmDisplayFrequency = refreshRate;
      fullscreenSettings.dmFields = DM_PELSWIDTH |
          DM_PELSHEIGHT |
          DM_BITSPERPEL |
          DM_DISPLAYFREQUENCY;
  
      SetWindowLongPtr(m_hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST);
      SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
      SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, displayWidth, displayHeight, SWP_SHOWWINDOW);
      isChangeSuccessful = ChangeDisplaySettings(&amp;fullscreenSettings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
      ShowWindow(m_hWnd, SW_MAXIMIZE);
  
      RECT rcWindow;
      GetWindowRect(m_hWnd, &amp;rcWindow);
  
      // calculate content position
      POINT ptDiff;
      ptDiff.x = ((rcWindow.right - rcWindow.left) - fullscreenWidth) / 2;
      ptDiff.y = ((rcWindow.bottom - rcWindow.top) - fullscreenHeight) / 2;
  
      AdjustWindowRectEx(&amp;rcWindow, GetWindowLong(m_hWnd, GWL_STYLE), FALSE, GetWindowLong(m_hWnd, GWL_EXSTYLE));
      SetWindowPos(m_hWnd, 0, ptDiff.x, ptDiff.y, displayWidth, displayHeight, NULL);
  
      return isChangeSuccessful;
  }
  </code></pre>