我用AppWinzard生成一个基于FormView的工程,现在,我想在这个form显示来之前,出来一个登陆对话框CRegister,应该将CRegister.domodal()放在哪呢?
还有就是如果输入不对,是哪条函数可以关掉这个主进程,让下面的from没显示出来之前,程序就自动结束了呢?

解决方案 »

  1.   

    在initialinstance中修改如下
    CLogin cc; if (cc.DoModal() ==IDOK)
    {
    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CMyDoc),
    RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    RUNTIME_CLASS(CMyView));
    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_SHOW);
    m_pMainWnd->UpdateWindow();

    }
    如果那个login框按下ok就,弹出下一个界面
    否则就结束了你也可以用类似的方法,如果正确就执行{}中的内容
    错了,就不执行这些就可以了
      

  2.   

    在工程的应用中。
    BOOL CEPoliceApp::InitInstance()
    {
    // 如果一个运行在 Windows XP 上的应用程序清单指定要
    // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
    //则需要 InitCommonControls()。否则,将无法创建窗口。
    InitCommonControls(); CWinApp::InitInstance(); // 初始化 OLE 库
    if (!AfxOleInit())
    {
    AfxMessageBox(IDP_OLE_INIT_FAILED);
    return FALSE;
    }
    AfxEnableControlContainer();
    // 标准初始化
    // 如果未使用这些功能并希望减小
    // 最终可执行文件的大小,则应移除下列
    // 不需要的特定初始化例程
    // 更改用于存储设置的注册表项
    // TODO: 应适当修改该字符串,
    // 例如修改为公司或组织名
    SetRegistryKey(_T("fdsafdsafdsfdsfdsafdssd"));
    LoadStdProfileSettings(4); 
    // if(!m_Db.Open (this->GetConnectionString (),_T("sa"),_T("sa")))
    // {
    // AfxMessageBox(_T("无法打开数据库!"));
    // }
    // 加载标准 INI 文件选项(包括 MRU)
    // 注册应用程序的文档模板。文档模板
    // 将用作文档、框架窗口和视图之间的连接

    if(!OpenDb())
    {
    AfxMessageBox(_T("连接数据库失败,请确定网络是否通畅,数据库服务器是否运行,用户名和密码是否正确!"));
    return FALSE;
    }
    if(!m_paramTable.Init(GetDb()))
    return FALSE; // 载入字典
    //CStringArray sa;
    //sa.Add("EP_Crossing");
    //sa.Add("EP_LicenceColor");
    //sa.Add("EP_VehicleType");
    //sa.Add("EP_PeccancyType");
    //if(!m_dict.Init(sa,GetDb(),NULL))
    //{
    // MessageBox(NULL,"初始化字典失败","初始化",MB_ICONERROR);
    // return FALSE;
    //}
    CSplashDlg dlg;
    if(dlg.DoModal ()==IDCANCEL)
    return FALSE;
    ....在闪屏类中调用登录对话框
    ..........
    BOOL CSplashDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // TODO:  在此添加额外的初始化
    SetTimer(1,1000,NULL);
    return TRUE;  // return TRUE unless you set the focus to a control
    // 异常: OCX 属性页应返回 FALSE
    }void CSplashDlg::OnTimer(UINT nIDEvent)
    {
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    KillTimer(1);
    CLogInDlg dlg;用户登录页面
    if(dlg.DoModal()==IDOK)
    {
    m_bOK=1;
    OnOK();
    }
    else
    {
    m_bOK=0;
    OnCancel();
    } //CDialog::OnTimer(nIDEvent);
    }