注册 登录
编程论坛 VC++/MFC

MFC中窗口的弹出,小弟新手

yangjinze 发布于 2012-04-08 20:22, 812 次点击
我是用MFC的基本对话框来做程序的,想要在登录窗口输入账号密码点击确认后,弹出主窗口,但每次输完点击后程序都直接关掉,下面是 CShangweijiAPP中INit**中我所写的代码,希望高手指教
CDengLu dlg;
    m_pMainWnd = &dlg;//程序运行首先启动登陆窗口
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with OK
        CShangweijiDlg zhu_dlg;//单击确定后出现程序主窗口
        zhu_dlg.DoModal();
    }
    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;
6 回复
#2
yangjinze2012-04-08 20:37
其中我对确定按钮有添加这些代码void CDengLu::OnOK() //登录窗口确定键的功能,判断输入的用户名与密码
{
    // TODO: Add extra validation here
    CString str_user;
    CString str_password;
    GetDlgItemText(IDC_EDIT_Name,str_user);
    GetDlgItemText(IDC_EDIT_PassWord,str_password);

    if(str_user.IsEmpty()||str_password.IsEmpty())//判断输入是否为空
    {
    MessageBox("用户名或者密码不能为空!");
    }

    else if(str_user=="123"&&str_password=="123")//测试账号密码123
    {
    //MessageBox("欢迎光临");
    //denglu=1;
   
   
    }
    else
    {
    MessageBox("用户名或者密码错误!");
    }
    CDialog::OnOK();
}
#3
zamboninite2012-04-09 13:05
CDengLu dlg;
   
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with OK
        CShangweijiDlg zhu_dlg;//单击确定后出现程序主窗口

        m_pMainWnd = &zhu_dlg;//注意这一行****************
        zhu_dlg.DoModal();
    }
#4
zamboninite2012-04-09 13:07
///// m_pMainWnd = &dlg;//程序运行首先启动登陆窗口
记得这一行要去掉啊
#5
yangjinze2012-04-09 16:41
回复 3楼 zamboninite
大哥不行啊
C:\Documents and Settings\Administrator\桌面\shangweiji\DengLu1.cpp(62) : error C2065: 'CShangweijiDlg' : undeclared identifier
#6
yangjinze2012-04-09 16:48
回复 3楼 zamboninite
高手谢谢啊,可以了,我写错位置了平
#7
yangjinze2012-04-09 16:55
回复 4楼 zamboninite
再次感谢
1