Simply add this method to your CGapiApplication-derived subclass and you should be all set...
- Code:
HRESULT CMyApplication::ToggleFullscreen()
{
HRESULT hr;
#ifndef _WIN32_WCE
// Close display
CloseDisplay();
// Close input
m_pInput->CloseInput();
if (GDDISPLAY_FULLSCREEN == (m_config.dwDisplayFlags & GDDISPLAY_FULLSCREEN))
{
// Restore caption
LONG nStyle;
nStyle = ::GetWindowLong(m_hWnd, GWL_STYLE);
nStyle |= WS_CAPTION;
::SetWindowLong(m_hWnd, GWL_STYLE, nStyle);
::ShowWindow(m_hWnd, SW_RESTORE);
m_config.dwDisplayFlags &= ~GDDISPLAY_FULLSCREEN;
m_config.dwDisplayFlags |= GDDISPLAY_WINDOW;
}
else
{
// Hide caption
LONG nStyle;
nStyle = ::GetWindowLong(m_hWnd, GWL_STYLE);
nStyle &= ~WS_CAPTION;
::SetWindowLong(m_hWnd, GWL_STYLE, nStyle);
::ShowWindow(m_hWnd, SW_SHOWMAXIMIZED);
m_config.dwDisplayFlags &= ~GDDISPLAY_WINDOW;
m_config.dwDisplayFlags |= GDDISPLAY_FULLSCREEN;
}
// ----- SET YOUR PREFERRED RESOLUTIONS BELOW -----
if (GDDISPLAY_FULLSCREEN == (m_config.dwDisplayFlags & GDDISPLAY_FULLSCREEN))
{
// Set fullscreen resolution
m_config.dwDisplayWidth = 640;
m_config.dwDisplayHeight = 480;
m_config.dwDisplayHz = 75;
// Disable window stretching
m_config.dwDisplayZoomWidth = 0;
m_config.dwDisplayZoomHeight = 0;
}
else
{
// Set windowed resolution
m_config.dwDisplayWidth = 240;
m_config.dwDisplayHeight = 320;
// Enable window stretching
m_config.dwDisplayZoomWidth = 480;
m_config.dwDisplayZoomHeight = 640;
}
// ------------------------------------------------
// Re-open display
if (FAILED(hr = OpenDisplay()))
{
m_bAppShouldExit = TRUE;
DestroyMainWindow();
return hr;
}
// Re-open input
if (FAILED(hr = m_pInput->OpenInput()))
{
m_bAppShouldExit = TRUE;
CloseDisplay();
DestroyMainWindow();
return hr;
}
// Allow subclass to create surfaces in system memory
if (!m_bAppShouldExit && FAILED(CreateSysMemSurfaces(m_pDisplay, m_config.hInstance)))
{
m_bAppShouldExit = TRUE;
}
// Allow subclass to create surfaces in video memory
if (!m_bAppShouldExit && FAILED(CreateVidMemSurfaces(m_pDisplay, m_config.hInstance)))
{
m_bAppShouldExit = TRUE;
}
// Restart the GapiDraw timer
m_pTimer->StartTimer(m_config.dwMaxFPS);
#endif
return GD_OK;
}