   How to copy an image in CDC into LPDIRECT3DDEVICE9?
  I drawed something in CDC,then do some  animations, but it shakeed, i am not satisfied.I want to copy the image in CDC into LPDIRECT3DDEVICE9,make use of DX to achive perfect image animations.I dont't know how to do this.   
  If you've got a IDirect3dSurface9 you can use IDirect3dSurface9::GetDC. Don't forget to call IDirect3dSurface9::ReleaseDC.Also note that does not work for uncommon color formats, does not do alpha and should not be done per frame.You can then access the returned HDC to BitBlt to for example. Don't hold onto the returned HDC.   ;Quote:Original post by EndurionIf you've got a IDirect3dSurface9 you can use IDirect3dSurface9::GetDC. Don't forget to call IDirect3dSurface9::ReleaseDC.Also note that does not work for uncommon color formats, does not do alpha and should not be done per frame.You can then access the returned HDC to BitBlt to for example. Don't hold onto the returned HDC.Thanks, but i am a beginner.Would you please tell me how to do in detail just like you said.   int Width = m_clientRect.right - m_clientRect.left;int Height = m_clientRect.bottom - m_clientRect.top;m_MemDC.CreateCompatibleDC(m_pDC); m_MemBitmap.CreateCompatibleBitmap(m_pDC, Width, Height); CBitmap *pOldBit=m_MemDC.SelectObject(&m_MemBitmap); m_MemDC.SetTextColor (RGB(255, 0, 0));m_MemDC.DrawText (_T("Test"), -1 , CRect (0, 0, 200, 100), DT_CENTER);HDC hdc = m_MemDC.GetSafeHdc();LPDIRECT3DSURFACE9 pSuf = NULL; HRESULT hr;hr = g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pSuf);hr = pSuf->GetDC(&hdc);    if (FAILED (g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,  D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0 ))){    return 0;}   if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ){    if(SUCCEEDED(InitVB()))  { g_pd3dDevice->SetStreamSource( 0, g_pVB, 0,    sizeof(CUSTOMVERTEX) );g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );if( FAILED(g_pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, 1 ))){    return 0;} if (FAILED (g_pd3dDevice->EndScene())){    return 0;} pSuf->ReleaseDC(hdc);g_pd3dDevice->Present( NULL, NULL, NULL, NULL );  }  m_MemBitmap.DeleteObject();m_MemDC.DeleteDC();   }   ;  From your description of using CDC I assumed you were prolifient using GDI. Sorry.Anyhow, here's how:int Width = m_clientRect.right - m_clientRect.left;int Height = m_clientRect.bottom - m_clientRect.top;m_MemDC.CreateCompatibleDC( m_pDC ); m_MemBitmap.CreateCompatibleBitmap( m_pDC, Width, Height ); CBitmap* pOldBit = m_MemDC.SelectObject( &m_MemBitmap ); m_MemDC.SetTextColor( RGB( 255, 0, 0 ) );m_MemDC.DrawText( _T( "Test" ), -1 , CRect( 0, 0, 200, 100 ), DT_CENTER );HDC hdc = m_MemDC.GetSafeHdc();LPDIRECT3DSURFACE9 pSuf = NULL;// clear before(!) blitting onto the HDCif ( FAILED( g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 ) ) ){  return 0;}HRESULT hr;hr = g_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pSuf );// TODO - Error checking!HDC hdcSurface;// TODO - Error checking!hr = pSuf->GetDC( &hdcSurface ); // blit data into surfaceBitBlt( hdcSurface, 0, 0, Width, Height, hdc, 0, 0, SRCCOPY );// release HDCpSuf->ReleaseDC( &hdcSurface );if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) ){  if ( SUCCEEDED( InitVB() ) )  {    g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );    g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );    if ( FAILED( g_pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, 1 ) ) )    { // TODO - you miss a call to EndScene here! return 0;    }    if ( FAILED( g_pd3dDevice->EndScene() ) )    { return 0;    }    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );  }}// always delete, not only if BeginScene succeedsm_MemBitmap.DeleteObject(); m_MemDC.DeleteDC();// also release the surface you received from GetBackBufferpSuf->Release();;Quote:Original post by EndurionFrom your description of using CDC I assumed you were prolifient using GDI. Sorry.Anyhow, here's how:*** Source Snippet Removed ***Thanks a lot.But nothing happened after run the code.m_MemDC.DrawText (_T("--Test--"), -1 , CRect (0, 0, 200, 100), DT_CENTER);My purpose is that "--Test--" can be showed through making use of LPDIRECT3DSURFACE9. Would you like to give me your E-mail, I will send this project to you, you can figure out what's wrong with the code.Thank you!   ;  I've sent you a reply. The code seems to be littered with a lot of attempts. I've commented out quite a few lines that weren't actively used. You should do a comparison of the code; I've only modified PlayWndDlg.cpp and .h.A hint: Try using the debug runtimes, I've removed a load of memory leaks. Also a note: Right now the displayed text wanders off the bottom, in that case a invalid rect is passed and StretchRect fails. You might want to catch that and disable drawing once you're off screen.Have fun!