W
W
WYCOR2013-05-09 10:28:11
C++ / C#
WYCOR, 2013-05-09 10:28:11

Using Direct2D In FullScreen?

Actually how?
On some site I read that Direct2D itself cannot translate into full-screen mode, so you need to use either the capabilities of WinAPI or direct3d.
Googled the code to convert to fullscreen:

void SetFullScreenMode(HWND hwnd)
{
  static WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) };
  DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
  if (dwStyle & WS_OVERLAPPEDWINDOW) {
    MONITORINFO mi = { sizeof(mi) };
    if (GetWindowPlacement(hwnd, &g_wpPrev) &&
        GetMonitorInfo(MonitorFromWindow(hwnd,
                       MONITOR_DEFAULTTOPRIMARY), &mi)) {
      SetWindowLong(hwnd, GWL_STYLE,
                    dwStyle & ~WS_OVERLAPPEDWINDOW);
      SetWindowPos(hwnd, HWND_TOP,
                   mi.rcMonitor.left, mi.rcMonitor.top,
                   mi.rcMonitor.right - mi.rcMonitor.left,
                   mi.rcMonitor.bottom - mi.rcMonitor.top,
                   SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
    }
  } else {
    //Перевод обратно в оконный режим
  }
}

And everything would be great, but the following direct2d code stops working in full screen mode
ID2D1Factory* pD2DFactory = NULL;
  HRESULT hr = D2D1CreateFactory(
    D2D1_FACTORY_TYPE_SINGLE_THREADED,
    &pD2DFactory);		
    
  // Obtain the size of the drawing area.
  RECT rc;
  GetClientRect(hWnd, &rc);

  // Create a Direct2D render target			
  ID2D1HwndRenderTarget* pRT = NULL;			
   hr = pD2DFactory->CreateHwndRenderTarget(
    D2D1::RenderTargetProperties(),
    D2D1::HwndRenderTargetProperties(
      hWnd,
      D2D1::SizeU(
        rc.right - rc.left,
        rc.bottom - rc.top)),
    &pRT);
  //Create a Brush
  ID2D1SolidColorBrush* pBlackBrush = NULL;
  if (SUCCEEDED(hr))
  {
  			
    pRT->CreateSolidColorBrush(
        D2D1::ColorF(D2D1::ColorF::Black),
        &pBlackBrush
        ); 
  }

Namely, SUCCEEDED(hr) returns false (in other words, CreateHwndRenderTarget() returns an error).
When I switch back to windowed mode, everything works again.
PS I'm just getting acquainted with WinAPI, direct2d, incl. if you can explain in the simplest possible way.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AxisPod, 2013-05-10
@AxisPod

Something tells me that the problem is in the pixel format. See what the D2D1::PixelFormat() function returns in fullscreen and windowed modes.

A
AxisPod, 2013-05-11
@AxisPod

The pixel format is how the video encodes characters, what bits are used for, you can set many different formats, for example, 16-bit, 32-bit, 48-bit, with several more variations, it all depends on your needs.
GetClientRect returns the rectangle of the window's client area, this is where you can draw. In this case, the coordinates are windowed, i.e. the upper left corner should be 0.0, the lower right is the size, if you need screen coordinates, you can convert it using the ClientToScreen method, there is also a reverse method, usually needed to work with the mouse.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question