DirectX 9 Surface::GetDC method

cuteddu

Newcomer
Joined
Jan 27, 2004
Messages
1
Has any been able to get the method GetDC() to work for a Direct3DSurface9 object? I'm trying to get the handle to the surface so I can use GDI to blit it to the screen for a Layered window. So I can get transparancy.

this is a snipit from what I've got so far:

Code:
LPDIRECT3DSURFACE9 pFrontBuffer;   
	m_pDevice->CreateOffscreenPlainSurface(640, 480, D3DFMT_R5G6B5,D3DPOOL_SYSTEMMEM, &pFrontBuffer,NULL);	

	if( D3D_OK != m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pFrontBuffer ) )
	{
		MessageBox( NULL, "Can't Get Back Buffer", "Error", MB_OK );
	}
	
	D3DXSaveSurfaceToFile("backbuf.bmp", D3DXIFF_BMP, pFrontBuffer, NULL, NULL);

	HDC D3Dhdc = CreateCompatibleDC( GetDC(NULL) );
	r = pFrontBuffer->GetDC( &D3Dhdc );	
	if( r != D3D_OK )
	{		
		if( r == D3DERR_INVALIDCALL )
			MessageBox( NULL, "Lock failed. Invalid Pointer to HDC", "", MB_OK );

	}

	HBITMAP Bitmap;
	Bitmap = CreateCompatibleBitmap( D3Dhdc, this->m_rcScreenRect.right, this->m_rcScreenRect.bottom );	

	if( Bitmap == NULL )
	{
		OutputDebugString( "Flipping Failed!\n" );
		MessageBox( NULL, "Can't Load Image", "Error", MB_OK );
	}

	SaveBitmap( "bitmap.bmp", Bitmap );
	
	HDC WindowDC = GetDC( m_hWnd );
	HDC memDC = CreateCompatibleDC( WindowDC  );
	SelectObject( memDC, Bitmap );

	TransparentBlt(WindowDC, 0, 0, this->m_rcScreenRect.right, this->m_rcScreenRect.bottom, memDC, 0, 0,this->m_rcScreenRect.right, this->m_rcScreenRect.bottom, RGB(0,0,255));
	ReleaseDC(  m_hWnd, WindowDC );
	DeleteDC( memDC );

	if( Bitmap != NULL )	
		DeleteObject( Bitmap );	
	
	if( D3Dhdc != NULL )
		m_pBackSurf->ReleaseDC( D3Dhdc );

Any help?
I've tried doing a Lock on the surface directly but I can't create a bitmap correctly with the info.

Thanks
 
Back
Top