Click to See Complete Forum and Search --> : How to get the DirectDraw(Window mode)'s hdc?


had
December 21st, 2003, 07:17 PM
BOOL InitDDraw(void)
{
DDSURFACEDESC ddsd;
HDC hdc;
if ( DirectDrawCreate( NULL, &lpDD, NULL ) != DD_OK ) return FALSE;

if ( lpDD->SetCooperativeLevel( NULL,
DDSCL_NORMAL ) != DD_OK)
return FALSE;

//if ( lpDD->SetDisplayMode( 1024, 768, 16 ) != DD_OK) return FALSE;

//UpdateWindow(GetActiveWindow());

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

if ( lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ) != DD_OK)
return FALSE;

if ( lpDDSPrimary->GetDC(&hdc) != DD_OK) return FALSE;

SetBkColor( hdc, RGB( 0, 0, 255 ) );
SetTextColor( hdc, RGB( 255, 255, 0 ) );
TextOut( hdc, 220, 200, szMsg1, lstrlen(szMsg1));
lpDDSPrimary->ReleaseDC(hdc);
return TRUE;

I want text out a string with TextOut(), I find I put it not in the window, just put out at Desktop, why?

galathaea
December 27th, 2003, 09:01 PM
I usually keep my GDI stuff pretty separate from DirectDraw. So I wouldn't get the DC from the surface, I'd get it from a GDI call on the window you are cooperating with (BeginPaint, GetDC, etc.). However, your problem stems from the fact that you are setting cooperative level with the window handle NULL, ie. you are cooperating with desktop, which is what you are seeing.

had
December 29th, 2003, 12:29 AM
Now, I know how to deal with it.

Just get the rect position of the window, then text out in the rect.