这是我的登陆窗口类的else分支
其功能为打开主界面,由于我的主界面是在CClientView里面画的
所以这里需要调用CClientView的OnInitialUpdate()函数
但不知道是不是这样而引起的错误
        //如果密码输入正确,则打开主界面
else
{
       //直接就是这句过不去,然后程序马上就死掉了
CClientView* pView=(CClientView*)((CMainFrame*)AfxGetApp()->m_pMainWnd)->GetActiveView(); pView->OnInitialUpdate();
CDialog::OnOK();
}

解决方案 »

  1.   

    不能再调用OnInitialUpdate()函数了,当视图第一次创建时系统自动调用,完成数据的初始化工作。
    若再在else里面再调用时,则会出现资源重复创建等内存泄漏情况,所以程序就死掉了。
      

  2.   

    代码用在哪了?默认的主窗口已经出现了?检查一下
    CClientView* pView=(CClientView*)((CMainFrame*)AfxGetApp()->m_pMainWnd)->GetActiveView();
    哪个指针无效。
      

  3.   

    试试在 CWinApp::InitInstance() 中显示登陆窗口。//显示登陆窗口(DoModal),如果 return FALSE,程序退出。
    m_pMainWnd->ShowWindow(SW_MAXIMIZE);
    m_pMainWnd->UpdateWindow();
      

  4.   


    我是在 CWinApp::InitInstance() 中显示登陆窗口的啊
    但是有个登陆时的"确定"按钮 我是做在登陆的类里面的
    所以在点击"确定"时 需要我说的那个else语句
      

  5.   

    不太明白 LZ 的意思,但在调用 m_pMainWnd->ShowWindow(SW_MAXIMIZE) 前 CClientView 的 OnInitialUpdate() 已经执行了,所以不需要再手动调用 OnInitialUpdate() 函数。
      

  6.   


    我现在不用执行OnInitialUpdate()了 之前的想法不太合理 
    现在关键是我用了
    m_pMainWnd->ShowWindow(SW_MAXIMIZE); 
    m_pMainWnd->UpdateWindow(); 
    程序界面出不来 只是闪一下就完了 这是怎么回事呢??
      

  7.   

    //如果不能输入正确的号码,才返回 FALSE,此时程序退出。
    if (IDOK != CLoginDialog.DoModal())
       return FALSE;m_pMainWnd->ShowWindow(SW_MAXIMIZE); 
    m_pMainWnd->UpdateWindow(); 
      

  8.   


    我也是这样做的 
    只是实现没有放在 CWinAPP里面 
    我是在我的CLoginDialog类里面实现的
    就出现了我说的那种  只是闪一下的问题 而没有出现窗口
      

  9.   

    窗口是闪了一下,程序就退出了?CWinApp 要返回 TRUE,程序才会继续运行。m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();return TRUE;
      

  10.   


    这个我知道,我是在 CLoginDialog::OnOk()
    里面去响应"确定"的 并没有在CWinApp里面去做.
      

  11.   

    m_pMainWnd->ShowWindow(SW_SHOW); //在这里断点,看看能否运行到这里。
      

  12.   


    CWnd* m_pMainWnd=((CMainFrame*)AfxGetApp()->m_pMainWnd);
    m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
    m_pMainWnd->UpdateWindow();
    CDialog::OnOK();能运行到m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
    只是看到窗口闪了一下 然后就消失了....
      

  13.   


    谢谢你的耐心啊 
    LWX300
      

  14.   

    相当抱歉,我不用 QQ、MSN 这些聊天软件的,你可以在 CSDN 发信给我就可以了。
      

  15.   

    我把代码贴出来了 这两个主要的地方/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////这是我的CLoginDlg的OnOk/////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    void CLoginDlg::OnOK() 
    { // TODO: Add extra validation here
    CPswdSet* m_recordset=new CPswdSet(&m_database);
    CString strSQL;
    UpdateData(TRUE);//读入用户输入的密码
    strSQL.Format("select * from password where PASSWORD='%s'",m_password);
    m_recordset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);//从数据库中查找,输入的密码是否正确
    if(m_recordset->GetRecordCount()==0)
    {
    if(count<3)
    {
    MessageBox("口令错误!","提示",MB_OK|MB_ICONINFORMATION);
    count++;//登录次数加1
    m_password.Empty();
    m_ctrlpassword.SetFocus();
    UpdateData(FALSE);
    }
    else
    {
    MessageBox("你无权使用此系统!","警告",MB_OK|MB_ICONHAND);
    m_database.Close();//关闭数据库
    CDialog::OnOK();//关闭对话框
    }
    }
    //如果登录成功,则打开主界面
    else
    {
    CWnd* m_pMainWnd=((CMainFrame*)AfxGetApp()->m_pMainWnd);
    m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
    m_pMainWnd->UpdateWindow();
    CDialog::OnOK();
    }}
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////这是我的CWinApp////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////BOOL CWinApp::InitInstance()
    {
    CAddressDlg dlg;
    m_pMainWnd = &dlg;
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
    }
    else if (nResponse == IDCANCEL)
    {
    }
    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 // Change the registry key under which our settings are stored.
    // TODO: You should modify this string to be something appropriate
    // such as the name of your company or organization.
    SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings();  // Load standard INI file options (including MRU) // Register the application's document templates.  Document templates
    //  serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CClientDoc),
    RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    RUNTIME_CLASS(CClientView));
    AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line
    if (!ProcessShellCommand(cmdInfo))
    return FALSE; // The one and only window has been initialized, so show and update it.
    /*
    m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
    m_pMainWnd->UpdateWindow();
    return TRUE;
    */}
      

  16.   


    //晕这个才是对的......
    //说明一下我的CLoginDlg为CAddressDlg..怕大家看不明白 所以说明一下
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////这是我的CAddressDlg/////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void CAddressDlg::OnOK() 
    {        // TODO: Add extra validation here
            CPswdSet* m_recordset=new CPswdSet(&m_database);
            CString strSQL;
            UpdateData(TRUE);//读入用户输入的密码
            strSQL.Format("select * from password where PASSWORD='%s'",m_password);
            m_recordset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);//从数据库中查找,输入的密码是否正确
            if(m_recordset->GetRecordCount()==0)
            {
                if(count<3)
                {
                    MessageBox("口令错误!","提示",MB_OK|MB_ICONINFORMATION);
                    count++;//登录次数加1
                    m_password.Empty();
                    m_ctrlpassword.SetFocus();
                    UpdateData(FALSE);
                }
                else
                {
                    MessageBox("你无权使用此系统!","警告",MB_OK|MB_ICONHAND);
                    m_database.Close();//关闭数据库
                    CDialog::OnOK();//关闭对话框
                }
            }
            //如果登录成功,则打开主界面
            else
            {
                CWnd* m_pMainWnd=((CMainFrame*)AfxGetApp()->m_pMainWnd);
                m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
                m_pMainWnd->UpdateWindow();
                CDialog::OnOK();
            }}
    ///////////////////////////////////////////////////////////////////////////////////////////
    ////////////这是我的CWinApp////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////BOOL CClientApp::InitInstance()
    {
        CAddressDlg dlg;
        m_pMainWnd = &dlg;
        int nResponse = dlg.DoModal();
        if (nResponse == IDOK)
        {
        }
        else if (nResponse == IDCANCEL)
        {
        }
        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    // Change the registry key under which our settings are stored.
        // TODO: You should modify this string to be something appropriate
        // such as the name of your company or organization.
        SetRegistryKey(_T("Local AppWizard-Generated Applications"));    LoadStdProfileSettings();  // Load standard INI file options (including MRU)    // Register the application's document templates.  Document templates
        //  serve as the connection between documents, frame windows and views.    CSingleDocTemplate* pDocTemplate;
        pDocTemplate = new CSingleDocTemplate(
            IDR_MAINFRAME,
            RUNTIME_CLASS(CClientDoc),
            RUNTIME_CLASS(CMainFrame),       // main SDI frame window
            RUNTIME_CLASS(CClientView));
        AddDocTemplate(pDocTemplate);    // Parse command line for standard shell commands, DDE, file open
        CCommandLineInfo cmdInfo;
        ParseCommandLine(cmdInfo);    // Dispatch commands specified on the command line
        if (!ProcessShellCommand(cmdInfo))
            return FALSE;    // The one and only window has been initialized, so show and update it.
    /*
        m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);    
        m_pMainWnd->UpdateWindow();
        return TRUE;
    */}
      

  17.   

    CAddressDlg dlg;
    m_pMainWnd = &dlg;
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
    }
    else if (nResponse == IDCANCEL)
    {
    }
    return FALSE; //InitInstance 返回 FALSE,程序直接退出了。
      

  18.   

    BOOL CClientApp::InitInstance()
    {
         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    // Change the registry key under which our settings are stored.
        // TODO: You should modify this string to be something appropriate
        // such as the name of your company or organization.
        SetRegistryKey(_T("Local AppWizard-Generated Applications"));    LoadStdProfileSettings();  // Load standard INI file options (including MRU)    // Register the application's document templates.  Document templates
        //  serve as the connection between documents, frame windows and views.    CSingleDocTemplate* pDocTemplate;
        pDocTemplate = new CSingleDocTemplate(
            IDR_MAINFRAME,
            RUNTIME_CLASS(CClientDoc),
            RUNTIME_CLASS(CMainFrame),       // main SDI frame window
            RUNTIME_CLASS(CClientView));
        AddDocTemplate(pDocTemplate);    // Parse command line for standard shell commands, DDE, file open
        CCommandLineInfo cmdInfo;
        ParseCommandLine(cmdInfo);    // Dispatch commands specified on the command line
        if (!ProcessShellCommand(cmdInfo))
            return FALSE;    // The one and only window has been initialized, so show and update it.
       CAddressDlg dlg;
       if (IDOK != dlg.DoModal())
          return FALSE;    m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);    
        m_pMainWnd->UpdateWindow();
        return TRUE;
    }void CAddressDlg::OnOK() 
    {        if(m_recordset->GetRecordCount()==0)
            {
                if(count<3)
                {
                  ...
                  return;
                }
                else
                {
                   ...
                     CDialog::OnCancel();//关闭对话框
                 }
            }
            //如果登录成功,则打开主界面
            CDialog::OnOK();
    }
      

  19.   

    void CAddressDlg::OnOK() 
    {         if(m_recordset->GetRecordCount()==0) 
            { 
                if(count <3) 
                { 
                  ... 
                  return; 
                } 
                else 
                { 
                  ... 
                    CDialog::OnCancel();//关闭对话框 
                     return; //再加上这句。
                } 
            } 
            //如果登录成功,则打开主界面 
            CDialog::OnOK(); 

      

  20.   

      CDialog::OnOK(); 这一句有问题,调用后直接退出程序了,不闪才怪
      

  21.   


    还在调呢  不过界面窗口跟登陆窗口是一起出来的哦 有点BUG
      

  22.   


    BOOL CClientApp::InitInstance() 

    CAddressDlg dlg; 
    if (IDOK != dlg.DoModal()) 
    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 

        // Change the registry key under which our settings are stored. 
        // TODO: You should modify this string to be something appropriate 
        // such as the name of your company or organization. 
        SetRegistryKey(_T("Local AppWizard-Generated Applications")); 

        LoadStdProfileSettings();  // Load standard INI file options (including MRU) 

        // Register the application's document templates.  Document templates 
        //  serve as the connection between documents, frame windows and views. 

        CSingleDocTemplate* pDocTemplate; 
        pDocTemplate = new CSingleDocTemplate( 
            IDR_MAINFRAME, 
            RUNTIME_CLASS(CClientDoc), 
            RUNTIME_CLASS(CMainFrame),      // main SDI frame window 
            RUNTIME_CLASS(CClientView)); 
        AddDocTemplate(pDocTemplate); 

        // Parse command line for standard shell commands, DDE, file open 
        CCommandLineInfo cmdInfo; 
        ParseCommandLine(cmdInfo); 

        // Dispatch commands specified on the command line 
        if (!ProcessShellCommand(cmdInfo)) 
            return FALSE; 

        // The one and only window has been initialized, so show and update it. 
        m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);    
        m_pMainWnd->UpdateWindow(); 
        return TRUE;