MFC, C++: continuing execution in a block of code that calls a dialog's DoModal(), without closing the dialog to the user
Posted on 2007-11-19
I'm having a small MFC related problem I hoped one of you could help me with.
I'm writing a database front-end.
The first thing the user sees is an authentication dialog. This is done in my main application class:
if(Login.m_bTerminate) // if the user pressed cancel (actually, he'd still call OnOK(), but change this bool)
// (try/ catch block for database connectivity). if it fails, we goto "start".
Login.DestroyWindow(); // we have our connection, lets destroy the dialog
How this appears to the user is:
1. He enters his authentication details.
2. He presses OK, and waits up to a few seconds without it being immediately evident that anything is happening - you can't see anything that relates to my application - not the authentication dialog, because it's OnOK() has been called, and not the main window (yet), because it has yet to be initialised.
I'd like to only have the authentication dialog disappear only when the database object has been successfully instantiated, so the user isn't left hanging for several seconds, wondering where the program has gone.
How can this be done?
I thought I could call Login's OnOK() after the database connection was established, but I'm not aware of any way to make execution continue in the main application block without making the dialog disappear.
While the DB connection object is instantiated on the heap, I'd still rather do this within my main application class, because I've already implemented an assessor method within that class, which is already used extensively in many other views and dialogs.
What should I do?