Hi guys, I am writing project for bank operation in MFC, before running my application i have to check the username and password. But i have some problem in my code, my main frame window is closed after enter username and password.Any one tell me the reason.....

class CLoginDialog : public CDialog //MyDialog class
{
   ////
};

class CBankApp : public CWinApp
{
public:
  CBankApp();
  ~CBankApp();
   BOOL InitInstance();
}
CBankFrameWnd : public CFrameWnd
CBankApp::CBankApp
{
}
CBankApp::~CBankApp()
{
}
BOOL CBankApp::InitInstance()
{
   CLoginDialog *pDlg = new CLoginDialog();
   m_pMainWnd = pDlg;
   if(pDlg->DoModal() == IDOK)
   {
      //Verify userName password, 
               if Valid User then assign frame window in m_pMainwnd and return TRUE ...
       CBankFrameWnd *pWnd = new CBankFrameWnd();
       m_pMainWnd = pWnd;
       pWnd -> ShowWindow(m_nCmdShow);
       pWnd -> UpdateWindow();
       return TRUE;
   }
   else
       return FALSE;
}

Thanks in Advance

Please post your line 27's actual code. Also, do you have your DDX function and Message Map declared and defined? These are 2 key steps for any MFC app.

Edited 6 Years Ago by LevyDee: n/a

line 27 is command line
// if Valid User then assign frame window in m_pMainwnd and return TRUE ...

Don't set m_pMainWnd to point to the dialog object, because during the execution of DoModal() , MFC does a PostQuitMessage() via the dialog's OnNcDestroy() (if m_pMainWnd points to the window being destructed). So, the program terminates as soon as the posted WM_QUIT gets extracted from the message queue, even though you've created the frame window.

Then, it's not necessary to allocate the dialog object on the heap .. I think the following should work ..

BOOL CBankApp::InitInstance()
{
   CLoginDialog Dlg;

   if(Dlg.DoModal() != IDOK)
      return FALSE;

   CBankFrameWnd *pWnd = new CBankFrameWnd();
   m_pMainWnd = pWnd;
   pWnd -> ShowWindow(m_nCmdShow);
   pWnd -> UpdateWindow();

   return TRUE;
}

Edited 6 Years Ago by mitrmkar: n/a

This article has been dead for over six months. Start a new discussion instead.