Sign in to follow this  
Nonameo

Drawing on an existing window

Recommended Posts

Hi guys. You probably get this a lot but all the examples i've found are very misleading. I dont know much (at all) about directx etc.. so please bear with me. What i'm trying to do: I want to draw a red square onto an existing window. Say for example, i have it's hWnd, i then want to render the square onto that window without the WM_PAINT method of the window erasing my square (thus my square will not flicker). Is this possible? Can anyone provide an example (or point me to one) that i can work with to produce this? Thanks a lot -Nonameo-

Share this post


Link to post
Share on other sites
I'm doing exactly this, though in MFC, and it's actually pretty straightforward. The big gotcha for me was to override the WM_ERASEBKGND message to do nothing; the default window proc will erase the whole window for you, which is likely to cause flickering.

My rudimentary creation code is something like this:


CRect rect;
GetClientRect( &rect );

HWND hWnd = GetSafeHwnd();

m_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
if( NULL == m_pD3D )
{
AfxMessageBox( "Failed to init D3D\n" );
return;
}

ZeroMemory( &m_d3dpp, sizeof(m_d3dpp) );
m_d3dpp.Windowed = TRUE;
m_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
m_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
m_d3dpp.EnableAutoDepthStencil = TRUE;
m_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

// Create the D3DDevice
if( FAILED( m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&m_d3dpp, &m_pd3dDevice ) ) )
{
AfxMessageBox( "Failed to init D3D\n" );
return;
}



Good luck!
Geoff

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this