Jump to content
  • Advertisement
Sign in to follow this  
Smit

Win32: Toggling fullscreen mode

This topic is 4526 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've written a function into my window class to toggle the window style and desktop resolution between fullscreen and windowed mode. However after going to fullscreen and then back to windowed the window doesn't close/max/min anymore, it just does nothing. Here is the code I'm using:
bool CRenderWindow::ToggleFullscreen( bool bFlag )
{
	LONG	lStyle;		
	LONG	lExStyle;	
	DEVMODE dmScreen;	
	
	lStyle = GetWindowLong( this->m_hWnd, GWL_STYLE );		
	lExStyle = GetWindowLong( this->m_hWnd, GWL_EXSTYLE );	

	if( bFlag == true )
	{
		lExStyle &= ~WS_EX_WINDOWEDGE;  
		lStyle &= ~WS_OVERLAPPEDWINDOW; 
		lStyle |= WS_POPUP;				
		lStyle |= WS_SYSMENU;			

		dmScreen.dmSize = sizeof( dmScreen );
		dmScreen.dmPelsWidth = this->m_nWidth;
		dmScreen.dmPelsHeight = this->m_nHeight;
		dmScreen.dmBitsPerPel = this->m_nBPP;
		dmScreen.dmFields = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;

		SetWindowLong( this->m_hWnd, GWL_STYLE, lStyle );
		SetWindowLong( this->m_hWnd, GWL_EXSTYLE, lExStyle );

		SetWindowPos( this->m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED );

		if( ChangeDisplaySettings( &dmScreen, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL )
		{
			MessageBox( NULL, "ChangeDisplaySettings() Failed!", "Error", MB_OK );
		}
	}
	else
	{
		lExStyle |= WS_EX_WINDOWEDGE;
		lStyle |= WS_OVERLAPPEDWINDOW;
		lStyle &= ~WS_POPUP;

		SetWindowLong( this->m_hWnd, GWL_STYLE, lStyle );
		SetWindowLong( this->m_hWnd, GWL_EXSTYLE, lExStyle );

		SetWindowPos( this->m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED );

		ChangeDisplaySettings( NULL, NULL );
	}

	return false;
}

Share this post


Link to post
Share on other sites
Advertisement
Try getting rid of that SW_NOSIZE and set the size and position of the window anyways... does it still happen? Another thing is you should probably keep the WS_POPUP style and just add the caption and buttons to it so you can use AjustWindowRect to make sure that your client area's aspect ratio doesn't change during the switch.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!