Invisible Background at Pop Up

Started by
3 comments, last by Lenox 18 years, 5 months ago
Hey there, Lenox here. I made this ( very ) simple application that uses Direct3D to...well, pop up a black window. The problem is this: When I start up the application, the window does popup but the background is invisible and some of the name in the start bar is shown ( See Figure 1 ). I can fix the problem by minimizing it. ( The window should look as it does in Figure 2 ) Here's some code to go along with all of this. Direct3D.Cpp

HRESULT Direct3D::Go()
{

	pD3D9 = Direct3DCreate9( D3D_SDK_VERSION );

	if( !pD3D9 )
	{
		throw std::runtime_error( "Failed to initialize Direct3D." );
		return E_FAIL;
	}

	D3DDISPLAYMODE d3ddm;
	D3DPRESENT_PARAMETERS d3dpp;

	ZeroMemory( &d3dpp, sizeof( D3DPRESENT_PARAMETERS ) );

	pD3D9->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );	

	d3dpp.hDeviceWindow					=				GetInfo()->_hwnd;
	d3dpp.BackBufferWidth				=				GetInfo()->_width;
	d3dpp.BackBufferHeight				=				GetInfo()->_height;
	d3dpp.Windowed						=				GetInfo()->_windowed;
	d3dpp.BackBufferFormat				=				d3ddm.Format;
	d3dpp.BackBufferCount				=				1;
	d3dpp.SwapEffect					=				D3DSWAPEFFECT_DISCARD;
	d3dpp.EnableAutoDepthStencil		=				true;
	d3dpp.AutoDepthStencilFormat		=				D3DFMT_D16;
	d3dpp.FullScreen_RefreshRateInHz	=				D3DPRESENT_RATE_DEFAULT;
	d3dpp.PresentationInterval			=				D3DPRESENT_INTERVAL_IMMEDIATE;

	if( pD3D9->CreateDevice(	D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dpp.hDeviceWindow,
								D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED,
								&d3dpp, &pD3DDevice9 ) != D3D_OK )
	{
		iLogger.Write( "status", "Failed to create the Direct3D Device" );
		throw std::runtime_error( "Failed to create the device." );
		return E_FAIL;

	};

	iLogger.Write( "status","Direct3D Initialized" );

	return S_OK;
};


Window.hpp

				inline HRESULT Register( WindowInfo * x)
				{
					WNDCLASSEX _class;

					_class.cbSize			=			sizeof( WNDCLASSEX );
					_class.style			=			CS_HREDRAW | CS_VREDRAW;
					_class.lpfnWndProc		=			x->_wndProc;
					_class.cbClsExtra		=			NULL;
					_class.cbWndExtra		=			NULL;
					_class.hInstance		=			x->_hinstance;
					_class.hIcon			=			LoadIcon( NULL, IDI_APPLICATION );
					_class.hCursor			=			LoadCursor( NULL, IDC_ARROW );
					_class.hbrBackground	=			(HBRUSH)GetStockObject( BLACK_BRUSH );
					_class.lpszMenuName		=			NULL;
					_class.lpszClassName	=			x->_winType.c_str();
					_class.hIconSm			=			LoadIcon( NULL, IDI_WINLOGO );

					if( !RegisterClassEx( &_class ) )
					{
						iLogger.Write( "status","Failed to register the window class." );
						throw std::runtime_error( "Failed to register the window class." );
						return E_FAIL;
					};

					iLogger.Write( "status","Window class registered successfully." );

					return Create( _class , x);
				};

				HRESULT Create( WNDCLASSEX _class , WindowInfo *x)
				{
					HWND hWnd = NULL;
					
					hWnd = CreateWindow(	_class.lpszClassName,
											x->_name.c_str(),
											x->_style,
											CW_USEDEFAULT,
											x->_y,
											x->_width,
											x->_height,
											NULL,
											NULL,
											x->_hinstance,
											NULL );
					if( !hWnd )
					{
						iLogger.Write( "status","Failed to create the window." );
						throw std::runtime_error( "Failed to create the window." );
						return E_FAIL;
					};

					iLogger.Write( "status","Window created successfully." );
					
					
					_init->PassHWND( hWnd );
					return _init->Go();
				};


Any help would be appreciated, Thank you. [Edited by - Lenox on November 20, 2005 2:28:03 PM]
Advertisement
1) Make sure you're pumping window messages (PeekMessage/GetMessage/DispatchMessage) when you get them - and in the same thread as your window. Process them in a timely manner if you want your UI to update in a timely manner.

2) Also ensure that any window messages you recieve which your application doesn't process get passed on to DefWindowProc().

3) Call UpdateWindow() immediately after calling ShowWindow(), this will send paint messages to the window so that it'll re-paint using the black brush set in your window class (which is also why points 1 & 2 are important - if you don't handle WM_PAINT but also don't pass it on, the window won't paint, and if you don't pump messages, you won't recieve the message in the first place [shortly before Windows flags your app as "Not Responding"]).

4) Of course, for the DirectX part off your application:
- what you see is what you Present(), remember to present what's been rendered.
- you should Clear() before you render; including the Z buffer if you've enabled depth/stencil testing.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Quote:Original post by S1CA1) Make sure you're pumping window messages (PeekMessage/GetMessage/DispatchMessage) when you get them - and in the same thread as your window. Process them in a timely manner if you want your UI to update in a timely manner.

2) Also ensure that any window messages you recieve which your application doesn't process get passed on to DefWindowProc().

3) Call UpdateWindow() immediately after calling ShowWindow(), this will send paint messages to the window so that it'll re-paint using the black brush set in your window class (which is also why points 1 & 2 are important - if you don't handle WM_PAINT but also don't pass it on, the window won't paint, and if you don't pump messages, you won't recieve the message in the first place [shortly before Windows flags your app as "Not Responding"]).

4) Of course, for the DirectX part off your application:
- what you see is what you Present(), remember to present what's been rendered.
- you should Clear() before you render; including the Z buffer if you've enabled depth/stencil testing.


Thank you for your help, the problem was that I was never actually calling ShowWindow, for one reason:

From past experiences, I never HAD to use ShowWindow or UpdateWindow, Direct3D would always ( seem ) to take care of that for me.

[EDIT]

Well, now that I look again, there's still the problem with the start bar, it only shows a little bit of the name if I don't minimize or anything.
Quote:Original post by Lenox
Quote:Original post by S1CA1) Make sure you're pumping window messages (PeekMessage/GetMessage/DispatchMessage) when you get them - and in the same thread as your window. Process them in a timely manner if you want your UI to update in a timely manner.

2) Also ensure that any window messages you recieve which your application doesn't process get passed on to DefWindowProc().

3) Call UpdateWindow() immediately after calling ShowWindow(), this will send paint messages to the window so that it'll re-paint using the black brush set in your window class (which is also why points 1 & 2 are important - if you don't handle WM_PAINT but also don't pass it on, the window won't paint, and if you don't pump messages, you won't recieve the message in the first place [shortly before Windows flags your app as "Not Responding"]).

4) Of course, for the DirectX part off your application:
- what you see is what you Present(), remember to present what's been rendered.
- you should Clear() before you render; including the Z buffer if you've enabled depth/stencil testing.


Thank you for your help, the problem was that I was never actually calling ShowWindow, for one reason:

From past experiences, I never HAD to use ShowWindow or UpdateWindow, Direct3D would always ( seem ) to take care of that for me.


If you were using the sample framework, then they would have been calling it for you. Also the first Present() of your device would likely have caused a paint message to be sent which will have done the same thing.

Finally there is also a CreateWindow() flag you may have been using which tells the window to show itself as soon as it's created.

But anyway, for windowed applications, you should really always create your DirectX stuff /after/ CreateWindow() [and not from WM_CREATE* either] but before ShowWindow() and UpdateWindow() [which should usually always be called too]

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Thats another problem - I had set Windowed to false, but it still comes up in a window. This really confused me, but I decided to accept it for now.

[EDIT]

Well, now I fixed the menu bar thing ( Now it's just hidden, I specified SW_SHOWMAXIMIZED ). All bugs are fixed! Thanks.

This topic is closed to new replies.

Advertisement