views:

399

answers:

2

Hi,

I am developing an application for video recording and I want to overlay the video preview with a logo and recording timer.

I tried to run the full-screen application and everything worked fine. Then I tried to run the application as a regular Windows application and it returned an error.

Could anyone take a look at the code below if there's a way to modify it to run the application as a regular Windows app?

HRESULT CViewfinderRenderer::OnStartStreaming()
{
  HRESULT hr = S_OK;
  DDSURFACEDESC ddsd;

  m_pDD = NULL;

  //full screen settings
  hr = DirectDrawCreate(NULL, &m_pDD, NULL);
  hr = m_pDD->SetCooperativeLevel(m_hWnd, DDSCL_FULLSCREEN);

  ddsd.dwSize = sizeof(ddsd); 
  ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; 
  ddsd.ddsCaps.dwCaps = DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE;
  ddsd.dwBackBufferCount = 1;

  //end full screen settings

  //normal settings
  /*hr = DirectDrawCreate(NULL, &m_pDD, NULL);
  hr = m_pDD->SetCooperativeLevel(m_hWnd, DDSCL_NORMAL);

  ddsd.dwSize = sizeof(ddsd);
  ddsd.dwFlags = DDSD_BACKBUFFERCOUNT;
  ddsd.dwBackBufferCount = 1;*/
  //end normal settings

  hr = m_pDD->CreateSurface(&ddsd, &m_pSurface, NULL);
  if (hr != DD_OK) {
    return hr;
  }

  // Get backsurface
  hr = m_pSurface->EnumAttachedSurfaces(&m_pBackSurface, EnumFunction);

  return S_OK;
}
+2  A: 

What error did it return?

Also try this instead:

ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
OJ
+1  A: 

Even when running windowed, you need to create a primary surface, only it is not a flippable surface.

 //full screen settings
 hr = DirectDrawCreate(NULL, &m_pDD, NULL);
 hr = m_pDD->SetCooperativeLevel(m_hWnd, DDSCL_NORMAL);

 ddsd.dwSize = sizeof(ddsd); 
 ddsd.dwFlags = DDSD_CAPS; 
 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

Besides of creating a surface, most likely you will want to create a clipper for the window. For a complete sample see paragraph Running windowed in this GameDev article.

Suma
This is exactly what I suggested, but came an hour later!?
OJ
Yes, what you suggested, only somewhat improved and link to tutorial provided as an added value.
Suma