Jump to content
  • Advertisement
Sign in to follow this  
boolean010

Direct3D9: (ERROR) :GetClientRect Failed ? ** SOLVED **

This topic is 3620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get three errors after my program has ended. I'm using VS 2008, here are the errors that I get. I also have a second question. I should I order things at the top of program. includes, globals, prototypes, define. What order should I use. Thanks in advance. Direct3D9: (ERROR) :GetClientRect Failed ? Direct3D9: (ERROR) :GetClientRect Failed ? Direct3D9: (ERROR) :BitBlt or StretchBlt failed in Present
#define WIN32_LEAN_AND_MEAN

// INCLUDE ////////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>

// GLOBAL /////////////////////////////////////////////////////////////////////////////////
HWND main_window_handle = NULL;

LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
D3DPRESENT_PARAMETERS d3dpp; 

// PROTOTYPES /////////////////////////////////////////////////////////////////////////////
int D3D_Init( );
int D3D_Main( );
int D3D_Shutdown( );

LRESULT CALLBACK MsgProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance,
				    HINSTANCE hPrevInstance,
					LPSTR lpCmdLine,
					int nShowCmd )
{
	HWND hwnd = NULL;
	MSG msg = { 0 };

	// Register the window class.
	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, 
	GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
	"Direct3D Tutorial", NULL };

	if( !RegisterClassEx( &wc ) )
		return( -1 );

	// Create the application's window.
	hwnd = CreateWindow( "Direct3D Tutorial", "Direct3D Tutorial 01: CreateDevice", 
	WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
	GetDesktopWindow(), NULL, wc.hInstance, NULL );

	if( !hwnd )
		return( -1 );

	main_window_handle = hwnd;

	ShowWindow( hwnd, nShowCmd );
	UpdateWindow( hwnd );

	D3D_Init( );
	while ( 1 )
	{
		if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
		{
			if( msg.message == WM_QUIT )
				break;

		    TranslateMessage( &msg );
		    DispatchMessage( &msg );
		} // end PeekMessage

		D3D_Main( );

	} // end while

    D3D_Shutdown( );
	return( msg.wParam );
}

LRESULT CALLBACK MsgProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	PAINTSTRUCT ps;

	switch( uMsg )
	{
	    case WM_DESTROY:
		{
			PostQuitMessage( 0 );
			return( 0 );
		} break;

		case WM_PAINT:
		{
			BeginPaint( hwnd, &ps );
			EndPaint( hwnd, &ps );
			return( 0 );
		} break;

		default:
			return DefWindowProc( hwnd, uMsg, wParam, lParam );

	} // end switch
}

int D3D_Init( )
{
	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	   return( -1 );

	ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    
	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, main_window_handle,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &g_pd3dDevice ) ) )
	    return( -1 );



	

	return( 0 );
}

int D3D_Main( )
{
	// Clear the back buffer to a blue color
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

	// Begin the scene
    g_pd3dDevice->BeginScene();

    // Rendering of scene objects happens here

    // End the scene
	g_pd3dDevice->EndScene();

	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );

	return( 0 );
}

int D3D_Shutdown( )
{
	if( g_pd3dDevice != NULL )
	{
	    g_pd3dDevice->Release( );
		g_pd3dDevice = NULL;
	}

	if( g_pD3D != NULL )
	{
	    g_pD3D->Release( );
		g_pD3D = NULL;
	}
	return( 0 );
}




[Edited by - boolean010 on June 30, 2008 1:21:04 PM]

Share this post


Link to post
Share on other sites
Advertisement
It looks like the problem is that you call D3D_Main() even when processing WM_QUIT - that is, even when the window no longer exists.

Share this post


Link to post
Share on other sites
Should I put in a else, to do something like this


if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( msg.message = WM_QUIT )
break;

TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
D3D_Main();
}



That is wierd, I put in the else statement and I don't get that error messages.
Thank you. How about my second question.

Share this post


Link to post
Share on other sites
No you should put your PeekMessage as the conditional of a while loop. The idea is that every frame (every iteration of your main while loop) you want to make sure all messages are handles before you fire off a render. Otherwise if your rendering takes a long time, your message queue will get backed up.

Share this post


Link to post
Share on other sites
Could you show me how to do that. I tried putting PeekMessage as the condition but the program shows the window for a sec and then quits.

Share this post


Link to post
Share on other sites
Sorry I meant inside your other while loop, like this:


bool quit = false;
while ( !quit )
{
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( msg.message == WM_QUIT )
quit = true;

TranslateMessage( &msg );
DispatchMessage( &msg );
} // end PeekMessage

D3D_Main( );

} // end while

Share this post


Link to post
Share on other sites
Hi, I am facing the same problem. I checked my message loop and it seems to be fine. The message loop is

 
while(msg.message != WM_QUIT)
{
if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
app.Render();

}
}



When I run it through the debugger, the errors that come up are:

Direct3D9: (ERROR) :GetClientRect Failed ?
Direct3D9: (ERROR) :GetClientRect Failed ?
Direct3D9: (ERROR) :BitBlt or StretchBlt failed in Present

Any ideas on what the problem might be?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!