Disabling Alt+F4
by Phoenix Online Studios · in Torque Game Engine · 02/01/2009 (1:18 pm) · 5 replies
Hello,
I would like to disable Alt+F4 functionality of closing the window, so that I can handle that binding via script. I have a GUI that prompts the user whether or not they are sure they want to quit, called: toggleQuit();
Does anyone know what should be modified in the engine source to stop the window from closing?
I would like to disable Alt+F4 functionality of closing the window, so that I can handle that binding via script. I have a GUI that prompts the user whether or not they are sure they want to quit, called: toggleQuit();
Does anyone know what should be modified in the engine source to stop the window from closing?
#2
Is the switch(wParam) inside of "case WM_SYSCOMMAND:" ?
Basically what's happening now is that when I press Alt+F4, it is performing the toggleQuit function. But when I click Yes on the Quit GUI, it does nothing. This is what I have in the Yes button code:
The variable is getting set, and the echo statement is being outputted, but for some reason the quit() is totally ignored.
02/01/2009 (6:52 pm)
Thanks James! It almost worked, and I'm actually running Torque 1.4.Is the switch(wParam) inside of "case WM_SYSCOMMAND:" ?
Basically what's happening now is that when I press Alt+F4, it is performing the toggleQuit function. But when I click Yes on the Quit GUI, it does nothing. This is what I have in the Yes button code:
function quitDlg::Yes_OnClick( %this )
{
$Game::HasConfirmedQuit = true;
echo("Yes button clicked");
quit();
}The variable is getting set, and the echo statement is being outputted, but for some reason the quit() is totally ignored.
#3
not just
02/01/2009 (7:20 pm)
Oops, that code snippet should be:if (!Con::getBoolVariable("Game::HasConfirmedQuit"))not just
if (!Con::getBoolVariable("HasConfirmedQuit"))
#4
02/01/2009 (7:25 pm)
And yes, that switch is in case WM_SYSCOMMAND:
#5
02/01/2009 (7:28 pm)
It works like a charm! Thanks again, James. :)
Torque Owner James Greenhalgh
Step 1.
Initialize a variable at the start of your game:
Step 2.
In winWindow.cc in the static LRESULT PASCAL WindowProc, you want the switch with the wParam to have a handler for SC_CLOSE
... switch(wParam) { case SC_CLOSE: Platform::postQuitMessage(0); return 0; case SC_KEYMENU: ...Step 3.
In the Platform::process of winWindow.cc, you'd want something like
... if(!ProcessMessages()) { if (!Con::getBoolVariable("Game::HasConfirmedQuit")) { Con::evaluatef("toggleQuit();"); return; } // generate a quit event Event quitEvent; ...Step 4.
Now I'm assuming your toggleQuit function prompts the player if they really want to quit or not, so what you want to do is if they confirm that they indeed want to quit you set then run a