PDA

View Full Version : Alt-F4 and ALT-Tab



madmark
02-28-2008, 12:13 AM
I searched the forum and examples but can't seem to find out how to correctly handle these commands. ALT-TAB is half handled as I handle the focus and no_focus signals but I don't see how to release the fullscreen mode to the desktop.

Seth
03-03-2008, 01:53 AM
Here is a little game example that uses 0.8 SVN and handles alt-tab, alt-enter to toggle fullscreen and alt-f4 (insty quit):

http://www.rtsoft.com/48/mrfun_hero_school.zip

A few places are Windows-centric (The SendMessage() commands) but you can #ifdef them out though...

Basically it does this in the main.cpp:




void App::ToggleWindowedMode()
{

if (m_pWindow->is_fullscreen())
{
m_pWindow->set_windowed();
m_pWindow->set_size(m_WindowDescription.get_size().width,m_Wi ndowDescription.get_size().height );


} else
{
m_pWindow->set_fullscreen(m_WindowDescription.get_size().widt h, m_WindowDescription.get_size().height, m_WindowDescription.get_bpp(), m_WindowDescription.get_refresh_rate());
//surfaces are now invalid. Rebuild them ?
//SetupBackground("media/title.jpGetApp()->GetMainWindow()->get_width(), GetApp()->GetMainWindow()->get_height());
}

ClearTimingAfterLongPause();
}

void App::OnLoseFocus()
{
m_HaveFocus = false;
SetupMouseClipping();
if (m_pWindow->is_fullscreen())
{
//m_pWindow->
SendMessage(m_Hwnd, WM_SYSCOMMAND, SC_MINIMIZE,0);
ChangeDisplaySettings(NULL, 0);
}
}

void App::OnGotFocus()
{
m_HaveFocus = true;
// m_bWindowResizeRequest = true; //draw background again
SetupMouseClipping();

if (m_pWindow->is_fullscreen())
{
m_pWindow->set_fullscreen(m_WindowDescription.get_size().widt h, m_WindowDescription.get_size().height, m_WindowDescription.get_bpp(), m_WindowDescription.get_refresh_rate());
}

}


void App::OnWindowClose()
{
m_bQuit = true; //quit the app ASAP
}

void App::OnKeyUp(const CL_InputEvent &key)
{
// if (GetMainWindow()->left_alt_down) || key.left_alt_down)
if(CL_Keyboard::get_keycode(CL_KEY_MENU))
{
//system message? We should really process these somewhere else
switch (key.id)
{

case CL_KEY_ENTER:
ToggleWindowedMode();
break;

case CL_KEY_F4:
OnWindowClose();

break;

}
return;
}
}

madmark
03-04-2008, 05:43 PM
Awesome, I will try this when I get home

Thanks!

UPDATE: Works like a champ, thanks again!