Game Development Reference
In-Depth Information
'
This might seem easy to code, but it can be a lot trickier than you think. Why? Let
s
look at the anatomy of the quit dialog. If you were coding a Windows application,
the code to bring up a message box looks like this:
int answer = MessageBox(_T(
Do you really want to quit?
),
_T(
Question
), MB_YESNO | MB_ICONEXCLAMATION);
When this code is executed, a message box appears over the active window and stays
there until one of the buttons is pressed. The window disappears, and the button ID is
sent back to the calling code. If you haven
'
t thought about this before, you should real-
ize that the regular message pump can
t be working, but clearly some message pump is
active, or the controls would never get their mouse and mouse button messages. How
does this work? The trick is to create another message pump that runs in a tight loop
and manage that within a method that handles the life cycle of a modal dialog box:
'
#define G_QUITNOPROMPT MAKELPARAM(-1,-1)
#define G_MSGENDMODAL (WM_USER+100)
int GameCodeApp::Modal(
shared_ptr<IScreenElement> pModalScreen, int defaultAnswer)
{
// If we
re going to display a dialog box, we need a human view
// to interact with.
HumanView *pView;
for(GameViewList::iterator i=m_pGame->m_gameViews.begin();
i!=m_pGame->m_gameViews.end(); ++i)
'
{
if ((*i)->VGetType()==GameView_Human)
{
shared_ptr<IGameView> pIGameView(*i);
pView = static_cast<HumanView *>(&*pIGameView);
break;
}
}
if (!pView)
{
// Whoops! There
s no human view attached.
return defaultAnswer;
'
}
assert(GetHwnd() != NULL && _T(
Main Window is NULL!
));
if ( ( GetHwnd() != NULL ) && IsIconic(GetHwnd()) )
{
FlashWhileMinimized();
}
Search WWH ::




Custom Search