PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Showing a non-MFC Dialog

jaybo_nomad · 17 Oct 2003, 04:24 UTC
I'm attempting to suspend GapiDraw and use normal, non-MFC dialog processing. Any suggestions why the code fragment below seems to hang in ::MessageBox() without displaying any part of the dialog?

I've tried various permutations of the calling sequence without success.

Related thread: http://www.pocketmatrix.com/forums/viewtopic.php?t=6601

Code:

HRESULT CMyApplication::ProcessNextFrame(CGapiSurface& backbuffer, DWORD dwFlags)
{
// Suspend GAPI and show a dialog
if (bShowADialog) {
m_display.SuspendDisplay ();
m_input.CloseInput (); // tried with and without this
ToggleFullscreen(this->m_hWnd, false);

::MessageBox (NULL, _T("Hey, does this work?"), _T("foobar"), MB_OKCANCEL);

bShowADialog = false;
m_display.ResumeDisplay ();
m_input.OpenInput();
ToggleFullscreen(this->m_hWnd, true);
}

// Normal ProcessNextFrame code follows...

[url][/url]
Pejo Software - Per · 17 Oct 2003, 06:58 UTC
Since there have been a lot of request about this and since I have it working in my game Beshaped wich doesn't use CGapiApplication, I might investigate on how to get it working with CGapiApplication. I will only do this if there isn't anybody else that can post a working solution here (Johan?) and if it is enough people interested in this.
I will not use Windows API message boxes and dialogs in my own future games because I think it will make the game look less professional.
Per: I think it would be great if you have the time! We are quite busy in getting the documentation for the Symbian release ready (and I have no code for showing message dialogs either)...
I think it shouldn't be too hard to make your own dialogs.

All you need to do is intercept all the event dispatching and painting, and send it to the dialog instead. If you are not using massive switch or if statements, and instead use classes as in the State design pattern, this isn't too hard to do.

So now you just need an appropriate data structure for your dialog. Basically, a class. It needs to know what to display (title, message, buttons) and where to display them (position and size). A few RECTs to store the button bounds are indicated.

It also needs to know how to behave. For example, it needs to know that clicking the cancel button should dismiss the dialog, and stuff like that.

Finally, it needs to know what to do when OK is clicked. An easy way to do this is to use the Command design pattern, and attach a command object to the dialog. The command is run when OK is clicked.

So you don't have a nested event loop, you just run your regular event loop, but events are redirected to the dialog instead. If you use the Chain of Responsibility pattern, then the dialog gets first chance to handle events, and if it doesn't, something else gets second chance, and so on.