Archived

This topic is now archived and is closed to further replies.

reaptide

Problem changing window settings

Recommended Posts

Hey everyone, I'm implementing the code to switch my window between Fullscreen and Windowed mode for use with OpenGL. It will switch between the two modes with no problem and setting fullscreen mode successfully sets the window to a popup (WS_POPUP). It is when switching back to windowed mode from fullscreen that there are problems. The window will regain its border and caption with no issues but will not properly resize. I'd like it to be 800x600 pixels but it is set to the registry screen size (In my case 1024x768).
    
//-------------------------------------------------------------------------------------------------

// CWindow::SetFullscreenMode()

//

// Description: 

//		Switches the window to fullscreen mode.

//

// Returns: 

//		1 on success, 0 on failure.

//-------------------------------------------------------------------------------------------------

int CWindow::SetFullscreenMode()
{
	if (!m_bFullscreen)
	{
		// Switch to fullscreen mode

		DEVMODE dmScreenSettings;
		ZeroMemory(&dmScreenSettings,     sizeof(dmScreenSettings));
		dmScreenSettings.dmSize			= sizeof(dmScreenSettings);
		dmScreenSettings.dmBitsPerPel	= 32;
		dmScreenSettings.dmPelsWidth	= 800;
		dmScreenSettings.dmPelsHeight	= 600;
		dmScreenSettings.dmFields		= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
		
		if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
			return(0);

		// Change the window style

		m_dwStyle = WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

		// Set the new window style

		SetWindowLong(m_hWnd, GWL_STYLE, m_dwStyle);

		// Change the size of the window

		if (!SetWindowPos(m_hWnd, HWND_TOP, 0, 0, 800, 600, NULL))
			return(0);

		// Display the widow

		ShowWindow(m_hWnd, SW_SHOWNORMAL);

		// Hide the cursor

		ShowCursor(FALSE);

		// Update the Fullscreen flag

		m_bFullscreen = TRUE;
	}
	
	return(1);
}

//-------------------------------------------------------------------------------------------------

// CWindow::SetWindowedMode()

// 

// Description:

//		Switches the window to windowed mode.

//

// Returns:

//		Returns 1 on success, 0 on failure

//-------------------------------------------------------------------------------------------------

int CWindow::SetWindowedMode()
{
	if (m_bFullscreen)
	{
		// Reset the Display

		ChangeDisplaySettings(NULL, 0);

		// Change the window style

		m_dwStyle = WS_VISIBLE | WS_BORDER | WS_MINIMIZE | WS_CAPTION | WS_SYSMENU | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

		// Set the new window style

		SetWindowLong(m_hWnd, GWL_STYLE, m_dwStyle);

		// Change the size of the window

		if (!SetWindowPos(m_hWnd, HWND_TOP, 0, 0, 800, 600, NULL))
			return(0);

		// Display the Cursor

		ShowCursor(TRUE);

		// Display the window

		ShowWindow(m_hWnd, SW_SHOWNORMAL);
		
		// Update the fullscreen flag

		m_bFullscreen = FALSE;
	}

	return(1);
}
     
Thanks for any help.
I am a signature virus. Please add me to your signature so that I may multiply. [edited by - Reaptide on March 15, 2003 11:08:00 PM] [edited by - Reaptide on March 17, 2003 4:06:14 PM]

Share this post


Link to post
Share on other sites
Seeing as this is about to fall off the page, I thought I would bump it up.

After a few hours of messing around I can''t seem to fix this issue. I''ve tried specifying different parameters for the functions in use and swapping the order that I perform them in, but I''m stumped. I could have swore that this technique has worked for me in the past.

Share this post


Link to post
Share on other sites
When changing from a full screen mode to a higher resolution windowed mode using DirectX, you must wait until after the display mode has changed before attempting to resize the window larger than your previous resolution, since you can''t make a window larger than the desktop. For example, when going from 640x480 full screen, to 1024x768, with an 800x600 window, you can''t set the window size larger than 640x480 until after the mode has been set to 1024x768.
From what you have described, this is not your problem, but I am posting this on the off chance that it might help.

Shawn

Share this post


Link to post
Share on other sites
Thanks for the suggestion, but I''m afraid it won''t help to much in this case. I''m not using DirectX.

I''m using Win32 Api to change the display settings.

But what you suggested does seem to be similair to what I am experiencing. I will have to take a look at ChangeDisplaySettings() to see if waits before the display settings change before returning.

Share this post


Link to post
Share on other sites
I seem to have fixed it. Goes to show that staring at your code for too long will not help fix a problem. It was just a typo on my part. When I change the window style WS_MINIMIZE to WS_MINIMIZEBOX everything worked as expected.

Thanks to my roomate for wondering why their was no minimize box on the title bar.



I am a signature virus. Please add me to your signature so that I may multiply.

Share this post


Link to post
Share on other sites