| home | |||
|
|||
| links |
|
||
|
developer's mag main page article part 1 part 2 part 3 part 4 part 5 part 6 part 7 part 8 part 9 |
4 - Parting WordsNow with this function, we can make our game more aware. For instance, when starting a game via the HandleMenu() function, we can check if a current game is being interrupted, and ask if we want to continue: case IDM_NEWGAME:
if ( ! CurrentlyPlaying() ) // go ahead?
NewGame(true);
else if ( 0==MessageBox("Quit current game?","Yes","No") )
NewGame(true);
break;
(Note: MessageBox() was developed in another column,
and of course requires adding the source
to the project.)The other check is when closing the program, which calls the window's Close() function, or the parent CWindow::Close() if not present. One problem with CWindow's default Close() function is that there is no provision to cancel the close. We can add this by creating our own Close():
void paTicTacToe::Close(void)
{
if ( !CurrentlyPlaying()
|| ( CurrentlyPlaying()
&& 0==MessageBox("Quit this program?","Yes","No") ) )
{
CWindow::Close();
GUI_Exit();
}
else // quit
{
GetCloseButton()->SetDownStatus( FALSE );
GUI_ClearStack();
}
}
The first line is the test for closing, using
our CurrentlyPlaying() call. Obviously, closing
is automatic if no game is on; if there is
a game in progress, the response from the
MessageBox() determines if we close. This
code combines both tests, and if successful
the parent's Close() is called, and the program
exits.The new feature is if the user decides to not quit. At this point, the function resets the window's close button, and clears the stack, undoing the close operation, and allowing the program to continue as normal. I recommend you place this code in all your programs, as it is the official way to prevent a close. As well, the ability to optionally quit lends a professional image to your software. Previous Section Next Section |
||
| Copyright © 2001-2006 ebmDevMag.com - Legal Notice | |||