How do I lock the surface in window mode?

Started by
1 comment, last by Crimson 23 years, 9 months ago
I just started using DirectDraw 7, and I created my game in fullscreen. I am trying to give it a window mode as well, but it keeps crashing when I call GetDC(). I basically used the example from the switcher program in the SDK for window mode. I even compiled the switcher program and it too crashes during GetDC when in Window Mode. Fullscreen is fine for my game and the switcher game. Does anyone know what I am doing wrong? I can show how I am initializing DirectDraw if it is needed. But it is identical to switcher and that runs fine if I use the EXE in the samples. Just doesn''t if I compile the source in examples. thanks
Advertisement
your problem is probably originating from the GetDC method. Are you getting the dc of the primary surface or the backbuffer?

you can''t lock the primary surface in windowed mode because well, the primary surface is shared by all other applications, and if you lock it, they can''t write to it.

the solution:
lock the back buffer (regardless of full/windowed).
___________________________Freeware development:ruinedsoft.com
Thanks for replying...but I am locking the back buffer.
So does the switcher program in the SDK. I forgot to mention
that Lock crashes the program also in Window mode.

Here is how I initialize DirectDraw in Window Mode:



// Get normal windowed mode
hRet = DirectDrawCreateEx(NULL, (VOID**)&g_pDD, IID_IDirectDraw7, NULL);
if (hRet != DD_OK)
return InitFail(hWndmain, hRet, "DirectDrawCreateEx FAILED");
hRet = g_pDD->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
if (hRet != DD_OK)
return InitFail(hWnd, hRet, "SetCooperativeLevel FAILED");

// Get the dimensions of the viewport and screen bounds
GetClientRect(hWnd, &g_rcViewport);
GetClientRect(hWnd, &g_rcScreen);
ClientToScreen(hWnd, (POINT*)&g_rcScreen.left);
ClientToScreen(hWnd, (POINT*)&g_rcScreen.right);


// Create the primary surface
ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL);
if (hRet != DD_OK)
return InitFail(hWnd, hRet, "CreateSurface FAILED");

// Create a clipper object since this is for a Windowed render
hRet = g_pDD->CreateClipper(0, &pClipper, NULL);
if (hRet != DD_OK)
return InitFail(hWnd, hRet, "CreateClipper FAILED");

// Associate the clipper with the window
hRet = pClipper->SetHWnd(0, hWnd);
if (hRet != DD_OK)
return InitFail(hWnd, hRet, "SetHWnd FAILED");
hRet = g_pDDSPrimary->SetClipper(pClipper);
if (hRet != DD_OK)
return InitFail(hWnd, hRet, "SetClipper FAILED");
pClipper->Release();
pClipper = NULL;

// Get the backbuffer. For fullscreen mode, the backbuffer was created
// along with the primary, but windowed mode still needs to create one.
ddsd.dwFlags = DDSD_WIDTH / DDSD_HEIGHT / DDSD_CAPS;
ddsd.dwWidth = 640;
ddsd.dwHeight = 480;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSBack, NULL);
if (hRet != DD_OK)
return InitFail(hWnd, hRet, "CreateSurface2 FAILED");

/////////////////////////////////////////////////////////

This code crashes the program in Window mode
g_pDDSBack->GetDC( &hdc );

This topic is closed to new replies.

Advertisement