
Displaying Dialog Box On the Main Window
In the InitInstance of your CWinApp-derived class:
After you have created and shown your main window, but before you exit the
InitInstance you can generate a modal dialog box. Based on the result of
that dialog you can decide to proceed or terminate the application. This is
loosely based on one of my programs:
// near the end of CMyApp::InitInstance
// finish mainframe activation
g_pMainFrame->ActivateFrame();
// temporarily disable the mainframe
g_pMainFrame->EnableWindow(FALSE);
// run the login dialog
if (!LoginUser())
{
// if login fail, terminate application
return FALSE;
}
else
{
// otherwise, enable the mainframe
g_pMainFrame->EnableWindow(TRUE);
return TRUE;
}
A simplified LoginUser looks something like this:
bool CMyApp::LoginUser()
{
// assume login failure
bool LoggedIn = false;
// our login dialog
LoginDlg dlg;
// run the login dialog
if (dlg.DoModal() == IDOK)
{
LoggedIn = true;
}
// return the result
return LoggedIn;
Quote:
}
HTH,
TFM3
Note: Spam-resistant e-mail address
Quote:
> Hello,
> I am very newbie for MFC environment. I am developing a MFC Based
> Application. Application main window is a document/view based MDI
> window.
> I want to do the following things,
> * Currently, when i start the application it shows the Main Window and
> Control
> goes to the Main Window. Now i need to show a Login Dialog Box
> (Modal) and
> this should get the inputs from users and validate the input and
> then finally
> control should go to the Main Window.
> Please provide me your idea's.
> Thanks in advance.
> Bye,
> Subramn