Original Post
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).
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]
//-------------------------------------------------------------------------------------------------
// 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);
}
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]