以下是我在基于对话框开发的一个程序,现在碰到的问题是我想在程序启动时首先启动登陆对话框,在登陆对话框内如果点击ok则顺利启动程序,如果点击cancel则程序启动结束,但我在以下代码中点击登陆对话框ok按扭后程序没能启动起来!!希望大家帮我看看这个问题是怎么回事!!谢谢BOOL CMyApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
} AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to      reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif CEnterDlg dlg1;
int nResponse = dlg1.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK

             CVideoCaptureDlg dlg;
     m_pMainWnd = &dlg;
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.
return FALSE;
}int CMyApp::ExitInstance() 
{
// TODO: Add your specialized code here and/or call the base class

return CWinApp::ExitInstance();
}

解决方案 »

  1.   

    CEnterDlg dlg1;
    int nResponse = dlg1.DoModal(); if (nResponse == IDCANCEL)
    {
                      return FALSE;
    }         CVideoCaptureDlg dlg;
    m_pMainWnd = &dlg; int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with Cancel
    }
      

  2.   

    CEnterDlg dlg1;
    int nResponse = dlg1.DoModal();
    if (nResponse == IDOK)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with OK

                 CVideoCaptureDlg dlg;
         m_pMainWnd = &dlg;
    }
    else if (nResponse == IDCANCEL)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with Cancel
    return  FALSE
    }
    我按照楼上老兄的方法试了,点击取消按扭可以中断程序启动,但点击ok却为啥不能正常启动程序呢,谢谢