I'm trying to understand how to change a windowed-window to a fullscreen-window at run time. What I do is use a DEVMODE structure with ChangeDisplaySettings when I want to make it fullscreen. I set the width and height to the width and height of the screen, which is fine. But what I want to know is how to change the resolution of the screen, not just the size of the display window, is there any way to do that?

You still use DEVMODE. The dmPelsWidth, dmPelsHeight, and dmBitsPerPel members are what you want to update.

When I change those members to something lower then my screen size, it shows the window borderless with the size I set, but the other parts of the screen are black instead of the windows background color, grey. Is there anyway to make it use the whole screen no matter what size if it's fullscreen?

I'm pretty sure I'm doing everything in there except for the OpenGL stuff, I'm not using that yet. Basically I have a Window 'Init' function, it goes like this:

bool CWindow::Init( HINSTANCE hInst, int width, int height, bool fullscreen, char *caption, WindowProcedure_t proc )
{
	RECT rScreenRect;
	RECT rWndRect = { 0, 0, width, height };

	// the actual size of the window, including menu
	int iWndWidth = ( rWndRect.right - rWndRect.left );
	int iWndHeight = ( rWndRect.bottom - rWndRect.top );

	// Register the windows class
	memset(&m_WindowClass, 0,	sizeof(m_WindowClass));

	m_WindowClass.cbSize			= sizeof(m_WindowClass);
	m_WindowClass.lpfnWndProc		= (WNDPROC)WindowProc;
	m_WindowClass.hInstance		= hInst;
	m_WindowClass.hCursor			= LoadCursor(0, IDC_ARROW);
	m_WindowClass.hbrBackground	= (HBRUSH) GetStockObject(LTGRAY_BRUSH);
	m_WindowClass.lpszClassName	= "WindowClass";

	if( !m_bRegistered )
	{
		if( !RegisterClassEx(&m_WindowClass) )
			return false;
		//m_bRegistered = true;
	}

	DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
	DWORD dwStyle = WS_OVERLAPPEDWINDOW;	

	if( fullscreen )
	{
		DEVMODE dmScreenSettings;
		memset( &dmScreenSettings, 0, sizeof( dmScreenSettings ) );
		dmScreenSettings.dmSize = sizeof( dmScreenSettings );
		dmScreenSettings.dmPelsWidth = width;
		dmScreenSettings.dmPelsHeight = height;
		dmScreenSettings.dmBitsPerPel = 32;
		dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

		if( ChangeDisplaySettings( &dmScreenSettings, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL )
			return false;

		dwExStyle = WS_EX_APPWINDOW;
		dwStyle = WS_POPUP;
		ShowCursor( FALSE );	
	}

	AdjustWindowRectEx( &rWndRect, dwStyle, false, dwExStyle );

	// Get the size of the window
	GetWindowRect( GetDesktopWindow(), &rScreenRect );

	int iX = ( (rScreenRect.right - rScreenRect.left) - iWndWidth ) >> 1;
	int iY = ( (rScreenRect.bottom - rScreenRect.top) - iWndHeight ) >> 1;

	m_pWindowHandle = CreateWindowEx( dwExStyle, "WindowClass", caption, dwStyle, 
		iX, iY, iWndWidth, iWndHeight, 
		NULL, 0, GetModuleHandle( 0 ), 0 );

	ShowWindow( m_pWindowHandle, SW_SHOW );
	UpdateWindow( m_pWindowHandle );

	m_nWidth = iWndWidth;
	m_nHeight = iWndHeight;
	m_bFullscreen = fullscreen;
	m_pModule = hInst;
	V_strncpy( m_WindowCaption, caption, 1024 );
	s_WindowProcedure = proc;

	return true;
}

Which works fine when in windowed mode, but does the thing I described when I try to switch to fullscreen. This is the function I call when I want to change the size/fullscreen state of the window:

NOTE: I have fullscreen as an int here to allow you to specify -1 to tell the function to not change the fullscreen state.

void CWindow::SetSize( int width, int height, int fullscreen )
{
	WindowProcedure_t temp = s_WindowProcedure;
	s_WindowProcedure = NULL;
	DestroyWindow( m_pWindowHandle );
	UnregisterClass( m_WindowClass.lpszClassName, m_pModule );

#define fs ( ( fullscreen == -1 ) ? m_bFullscreen : ( ( fullscreen == 1 ) ? true : false ) )

	if( !m_bFullscreen )
	{
		Init( m_pModule, width, height, fs, m_WindowCaption, temp );
		return;
	}

	int screenwidth = 1366; //GetSystemMetrics( SM_CXFULLSCREEN );
	int screenheight = 768; //GetSystemMetrics( SM_CYFULLSCREEN );

	Init( m_pModule, screenwidth, screenheight, fs, m_WindowCaption, temp );
}

Edited 5 Years Ago by tomtetlaw: n/a

This article has been dead for over six months. Start a new discussion instead.