• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
howie_007

No window frame when going from full screen back to windowed mode

10 posts in this topic

I have read through tons of post here on this subject and looked at numerous code examples and for the life of me, I can't get this to work correctly. As far as I can tell, I'm not doing anything different then what I have been seeing.

 

I start out in windowed mode and then change it to full screen mode and then change it back to windowed mode. Even though I'm resetting the styles via "SetWindowLong" and then calling "SetWindowPos", I'm left with a window with no window frame.

 

I've tested this ever way I can think of. Any idea of what I might be missing?

 

I define the styles in the constructor as class members...

CXWindow::CXWindow() :
...
windowedStyle(WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX),
windowedExStyle(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE),
fullScreenStyle(WS_POPUP|WS_VISIBLE),
fullScreenExStyle(WS_EX_TOPMOST)

 

This is how I create the window.

void CXWindow::CreateXWindow( const HINSTANCE hInst )
{
    uint dwExStyle;
    uint dwStyle;

	RECT rect;

	// Set the rect
    SetRect( &rect, 0, 0, (int)CSettings::Instance().GetSize().w, (int)CSettings::Instance().GetSize().h );

    if( CSettings::Instance().GetFullScreen() )
    {
        dwExStyle = fullScreenExStyle;
        dwStyle = fullScreenStyle;
    }
	else
    {       
        // Setup the styles
        dwExStyle = windowedExStyle;
        dwStyle = windowedStyle;   
    }
    
    // Create the window
    hWnd = CreateWindowEx( dwExStyle,
						   CSettings::Instance().GetGameWndClassName().c_str(),
						   "",
                           dwStyle,
						   rect.left,
						   rect.top,
                           rect.right,
						   rect.bottom,
                           NULL,
						   NULL,
						   hInst,
						   NULL );

	if( hWnd == NULL )
		throw NExcept::CCriticalException("Create Window Error",
			boost::str( boost::format("There was an error creating the game window.\n\n%s\nLine: %s") % __FUNCTION__ % __LINE__ ));

	if( !CSettings::Instance().GetFullScreen() )
	{
		// Adjust the rect so that the client size of the window is the exact size of the needed resolution
		AdjustWindowRectEx( &rect, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL, GetWindowExStyle(hWnd) );

		// Position the window in the center of the screen
		SetWindowPos( hWnd,
					  HWND_NOTOPMOST,
					  (GetSystemMetrics( SM_CXSCREEN ) - (rect.right-rect.left)) / 2, 
					  (GetSystemMetrics( SM_CYSCREEN ) - (rect.bottom-rect.top)) / 2,
					  rect.right - rect.left,
					  rect.bottom - rect.top,
					  SWP_NOACTIVATE );
	}

}   // CreateXWindow

 

I call this prior to resetting the DirectX device. I've even recalled it after the device was reset.

void CXWindow::ResetWindowStyle()
{
	if( CSettings::Instance().WasScreenModeChanged() )
	{
		uint dwExStyle = windowedExStyle;
		uint dwStyle = windowedStyle;

		if( CSettings::Instance().GetFullScreen() )
		{
			dwExStyle = fullScreenExStyle;
			dwStyle = fullScreenStyle;
		}

		// Change the windows styles
		SetWindowLong( hWnd, GWL_STYLE, dwStyle);
		SetWindowLong( hWnd, GWL_EXSTYLE, dwExStyle);
	}

}	// ResetWindowStyle

 

This is what I call after the device reset. One odd thing to note is that in this function, "AdjustWindowRectEx" does not change the rect like it does when the window was first created. The rect remains unchanged.

void CXWindow::ResetWindowSize()
{
RECT rect;

	// Set the rect
    SetRect( &rect, 0, 0, (int)CSettings::Instance().GetSizeChange().w, (int)CSettings::Instance().GetSizeChange().h );

	if( CSettings::Instance().WasResolutionChanged() || CSettings::Instance().WasScreenModeChanged() )
	{
		if( CSettings::Instance().WasResolutionChanged() )
		{
			// Recalculate the default size and ratio
			CSettings::Instance().CalcRatio( CSettings::Instance().GetSizeChange() );

			// Recalculate the projection matrixes
			CalcProjMatrix( CSettings::Instance().GetSizeChange(),
							CSettings::Instance().GetDefaultSize() );
		}

		if( !CSettings::Instance().WasScreenModeChanged() )
		{
			// Adjust the rect so that the client size of the window is the exact size of the needed resolution
			AdjustWindowRectEx( &rect, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL, GetWindowExStyle(hWnd) );

			// Position the window in the center of the screen
			SetWindowPos( hWnd,
						  HWND_TOP,
						  (GetSystemMetrics( SM_CXSCREEN ) - (rect.right-rect.left)) / 2, 
						  (GetSystemMetrics( SM_CYSCREEN ) - (rect.bottom-rect.top)) / 2,
						  rect.right - rect.left,
						  rect.bottom - rect.top,
						  SWP_FRAMECHANGED|SWP_SHOWWINDOW );
		}
	}

}	// ResetWindow
Edited by GameCodingNinja
0

Share this post


Link to post
Share on other sites

I see that you're resetting the window size, but did you reset the device as well?

There is no call to D3D Reset (or even your own custom implementation of Clear and CreateDevice).

Check this out.

0

Share this post


Link to post
Share on other sites

Thanks for the link but that example only deals with resizing the window. Everything I'm currently doing works fine except going from full screen to window mode.

 

Here are my reset functions.

void CGameTemplate::HandleDeviceReset( CSize<float> & res, bool vSync, bool windowed )
{
	// Free the shader(s)
	CShader::Instance().Free();

	// All things created by the device that is not managed need 
	// to be Released before the device can be reset
	CXWindow::Instance().HandleDeviceReset( res, vSync, windowed );

	// Reload and Enumerate through all the shaders to set their default values
	CShader::Instance().LoadFromXML( string("data/shaders/startup_shader_effects.cfg") );
	CShader::Instance().LoadFromXML( string("data/shaders/shader_effects.cfg") );
	CShader::Instance().EnumerateShaderInit();

}	// HandleDeviceReset

void CXWindow::HandleDeviceReset( CSize<float> & res, bool vSync, bool windowed )
{
    // function for releasing device created members for device
    // lost reset. The reset will error if these are not released
    ReleaseDeviceCreatedMembers();

    // Set the resolution
    dxpp.BackBufferWidth  = res.w;
    dxpp.BackBufferHeight = res.h;

    // Set the windowed/full screen mode
    dxpp.Windowed = windowed;

    // Set the vsync
    dxpp.PresentationInterval = vSync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;

    // All things created by the device that is not managed
    // need to be Released before the device can be reset
    if( spDXDevice->Reset( &dxpp ) == D3DERR_INVALIDCALL )
        throw NExcept::CCriticalException("DirectX Reset Error",
            boost::str( boost::format("Call to Reset() failed with D3DERR_INVALIDCALL!\n\n%s\nLine: %s") % __FUNCTION__ % __LINE__ ));

    // Buffers and render states that need to be reset/recreated during a device reset
    ResetXDevice();

}    // HandleDeviceReset

 

Here's the function for creating the DirectX device.

void CXWindow::CreateXDevice()
{
    D3DDISPLAYMODE dxdm;
    HRESULT hresult;
    D3DFORMAT depthFormat[] = {D3DFMT_D32, D3DFMT_D24X8, D3DFMT_D16, (D3DFORMAT)0};
    D3DFORMAT selectedDepthFormat;
    int counter = 0;

	// Set the initial buffer clear mask
	if( CSettings::Instance().GetClearTargetBuffer() )
		bufferClearMask = D3DCLEAR_TARGET;

	// Recored the max and min z distances
	maximumZDist = CSettings::Instance().GetMaxZdist();
	minimumZDist = CSettings::Instance().GetMinZdist();
	viewAngle = D3DXToRadian( CSettings::Instance().GetViewAngle() );

	// Calc the aspect ratio
	float aspectRatio = CSettings::Instance().GetSize().w / 
						CSettings::Instance().GetSize().h;

	// Calc the square percentage
    squarePercentage = CSettings::Instance().GetSize().h /
					   CSettings::Instance().GetSize().w;

	// calc the y ratio to the frustrum
    frustrumYRatio = squarePercentage / aspectRatio;

    // Create the DirectX 9 instance
    spDXInstance.reset( Direct3DCreate9( D3D_SDK_VERSION ) );

    if( spDXInstance.isNull() )
		throw NExcept::CCriticalException("DirectX Init Error",
			boost::str( boost::format("Error creating an instance of DirectX9.\n\n%s\nLine: %s") % __FUNCTION__ % __LINE__ ));

    // Get the caps to see if we can do hardware vertex processing
    if( FAILED( spDXInstance->GetDeviceCaps( D3DADAPTER_DEFAULT,
                                             D3DDEVTYPE_HAL,
                                             &d3dCaps ) ) )
		throw NExcept::CCriticalException("DirectX Init Error",
			boost::str( boost::format("Error getting device capabilities of video card.\n\n%s\nLine: %s") % __FUNCTION__ % __LINE__ ));

    // Get info about the video card
    if( FAILED( spDXInstance->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &dxdm ) ) )
		throw NExcept::CCriticalException("DirectX Init Error",
			boost::str( boost::format("Error getting adapter display mode of video card.\n\n%s\nLine: %s") % __FUNCTION__ % __LINE__ ));

    // Check for the best z buffer format
    do
    {
        selectedDepthFormat = depthFormat[counter];

        hresult = spDXInstance->CheckDeviceFormat( D3DADAPTER_DEFAULT,
                                                   D3DDEVTYPE_HAL,
                                                   dxdm.Format,
                                                   D3DUSAGE_DEPTHSTENCIL,
                                                   D3DRTYPE_SURFACE,
                                                   depthFormat[counter++] );
    }
    while( hresult != D3D_OK && depthFormat[counter] );

    // Tell them we couldn't secure a depth buffer
    if( hresult != D3D_OK )
		throw NExcept::CCriticalException("DirectX Init Error",
			boost::str( boost::format("Video card does not support depth buffering.\n\n%s\nLine: %s") % __FUNCTION__ % __LINE__ ));

    // clear out the structure
    memset( &dxpp, 0, sizeof(dxpp) );

	// Full screen or windowed mode
    dxpp.Windowed = !CSettings::Instance().GetFullScreen();

	// Fill out the remaining items of the structure
    dxpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
    dxpp.BackBufferFormat       = dxdm.Format;
    dxpp.BackBufferWidth        = (int)CSettings::Instance().GetSize().w;
    dxpp.BackBufferHeight       = (int)CSettings::Instance().GetSize().h;
	dxpp.hDeviceWindow          = hWnd;
	dxpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;

	if( CSettings::Instance().GetTripleBuffering() )
		dxpp.BackBufferCount = 2;

	if( CSettings::Instance().GetVSync() )
		dxpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

	// Do we need the depth stencil? Z buffer and stencil are both created at the same time in hardware
	if( CSettings::Instance().GetCreateDepthStencilBuffer() )
	{
		dxpp.EnableAutoDepthStencil = true;
		dxpp.AutoDepthStencilFormat = selectedDepthFormat;

		// check for stencil buffer support
		if( spDXInstance->CheckDepthStencilMatch( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, dxpp.BackBufferFormat, dxpp.BackBufferFormat, D3DFMT_D24FS8 ) != D3D_OK )
		{
			if( spDXInstance->CheckDepthStencilMatch( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, dxpp.BackBufferFormat, dxpp.BackBufferFormat, D3DFMT_D24S8 ) != D3D_OK )
			{
				if( spDXInstance->CheckDepthStencilMatch( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, dxpp.BackBufferFormat, dxpp.BackBufferFormat, D3DFMT_D24X4S4 ) != D3D_OK )
				{
					if( spDXInstance->CheckDepthStencilMatch( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, dxpp.BackBufferFormat, dxpp.BackBufferFormat, D3DFMT_D24FS8 ) != D3D_OK )
					{
						throw NExcept::CCriticalException("DirectX Init Error",
							boost::str( boost::format("Video card does not support hardware stencil buffer.\n\n%s\nLine: %s") % __FUNCTION__ % __LINE__ ));
					}
					else // support for a d15s1 buffer
					{
						dxpp.AutoDepthStencilFormat = D3DFMT_D15S1;
					}
				}
				else // support for a d24x4s4 buffer
				{
					dxpp.AutoDepthStencilFormat = D3DFMT_D24X4S4;
				}
			}
			else // support for a d24s8 buffer
			{
				dxpp.AutoDepthStencilFormat = D3DFMT_D24S8;
			}
		}
		else //support for a d24fs8 buffer
		{
			dxpp.AutoDepthStencilFormat = D3DFMT_D24FS8;
		}
	}

	DWORD dwBehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;

    if( d3dCaps.VertexProcessingCaps != 0 )    
        dwBehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;

    // Create the device
	LPDIRECT3DDEVICE9 pDXDev;
    if( FAILED( hresult = spDXInstance->CreateDevice( D3DADAPTER_DEFAULT,
                                         D3DDEVTYPE_HAL,
                                         hWnd,
                                         dwBehaviorFlags | D3DCREATE_MULTITHREADED,
                                         &dxpp, 
                                         &pDXDev ) ) )
	{
		DisplayError( hresult );
	}

	spDXDevice.reset(pDXDev);

	CalcProjMatrix( CSettings::Instance().GetSize(),
						CSettings::Instance().GetDefaultSize() );
	
    // Buffers and render states that need to be reset/recreated during a device rest
    ResetXDevice();

}   // CreateXDevice
Edited by GameCodingNinja
0

Share this post


Link to post
Share on other sites
To enable/disable the frame around the windows, you should set the hbrBackground value in your windowclass object. I.e set it to (HBRUSH)COLOR_WINDOW to disable it
0

Share this post


Link to post
Share on other sites

Thanks but unfortunately, that didn't solve my problem.

 

Here's my window registration function.

void CGameWnd::RegisterWnd( HINSTANCE hInstance,
			winCallbackFuncPtrType pWinCallback )
{
    WNDCLASSEX w;

    w.cbSize = sizeof( WNDCLASSEX );
    w.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_BYTEALIGNCLIENT;
    w.lpfnWndProc = pWinCallback;
    w.cbClsExtra = 0;
    w.cbWndExtra = 0;
    w.hInstance = hInstance;
    w.hIcon = LoadIcon( hInstance, "AppIcon" );
    w.hIconSm = NULL;
    w.hCursor = LoadCursor( NULL, IDC_ARROW );
    w.hbrBackground = NULL;
    w.lpszMenuName = NULL;
	w.lpszClassName = CSettings::Instance().GetGameWndClassName().c_str();

    if( RegisterClassEx(&w) == 0 )
		throw NExcept::CCriticalException("Register Class Window", "There was an error registering the class window.");

}   // Starter_RegisterWnd 

 

0

Share this post


Link to post
Share on other sites

That's too bad.
I don't know if setting it to NULL achieves any of the 2 goals you try to achieve.

What I do for windowed is not set it all (and that works) and when I'm in fullscreen I use (HBRUSH)COLOR_WINDOW. Maybe setting it to NULL is different then the default value

0

Share this post


Link to post
Share on other sites

I was able to come up with a solution.

 

My solution is not to use "SetWindowLong" because once you set a style that removes the window frame for full screen, you can't get the frame back by reapplying the style when switching back to windowed mode.

 

So my solution is to create a window with the desired window frame and when in full screen mode, eat the WM_NCPAINT message. This keeps the windows caption from flickering while in full screen mode.

 

It's not an elegant solution...

0

Share this post


Link to post
Share on other sites

If you change the frame with SetWindowLong you have to call SetWindowPos with SWP_FRAMECHANGED afterwards, so the changes get properly applied.

0

Share this post


Link to post
Share on other sites
If you change the frame with SetWindowLong you have to call SetWindowPos with SWP_FRAMECHANGED afterwards, so the changes get properly applied.

You would think. I tried that along with many other tests to no avail.

 

It works fine using SetWindowLong and SetWindowPos when going from window mode to full screen mode. It doesn't work when going from full screen mode back to window mode.

0

Share this post


Link to post
Share on other sites
Are you setting the new window style *after* resetting the device? All you need to do after resetting the device is call SetWindowLong() to set the new window style, and then SetWindowPos() with the SWP_FRAMECHANGED flag to flush the changes.
0

Share this post


Link to post
Share on other sites
Are you setting the new window style *after* resetting the device? All you need to do after resetting the device is call SetWindowLong() to set the new window style, and then SetWindowPos() with the SWP_FRAMECHANGED flag to flush the changes.

yep... I tried it before the reset... after the reset... before and after the reset. A zillion tests later, gave up.

 

Even though I removed some of the original posted code displayed above, I added the below test code (after the reset) just to reconfirm I'm not crazy and yep, no window frame. Unless there's something else I'm missing, the below code doesn't work.

if( !CSettings::Instance().GetFullScreenChange() )
{
	SetWindowLong( hWnd, GWL_STYLE, WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX );
	SetWindowLong( hWnd, GWL_EXSTYLE, WS_EX_WINDOWEDGE );

	// Adjust the rect so that the client size of the window is the exact size of the needed resolution
	AdjustWindowRectEx( &rect, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL, GetWindowExStyle(hWnd) );

	// Position the window in the center of the screen
	SetWindowPos( hWnd,
			HWND_NOTOPMOST,
			((GetSystemMetrics( SM_CXSCREEN ) - (rect.right-rect.left)) / 2), 
			((GetSystemMetrics( SM_CYSCREEN ) - (rect.bottom-rect.top)) / 2),
			rect.right - rect.left,
			rect.bottom - rect.top,
			SWP_SHOWWINDOW|SWP_FRAMECHANGED );
}
else
{
	SetWindowLong( hWnd, GWL_STYLE, WS_POPUP|WS_VISIBLE );
	SetWindowLong( hWnd, GWL_EXSTYLE, WS_EX_TOPMOST );

	SetWindowPos( hWnd,
			HWND_NOTOPMOST,
			0, 
			0,
			0,
			0,
			SWP_SHOWWINDOW|SWP_FRAMECHANGED|SWP_NOSIZE );
}
Edited by GameCodingNinja
0

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  
Followers 0