首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

MFC编的 求帮批改

2013-12-30 
MFC编的 求帮修改本帖最后由 derekrose 于 2013-12-27 11:50:22 编辑BOOL CMy0000App::InitInstance(){Afx

MFC编的 求帮修改
本帖最后由 derekrose 于 2013-12-27 11:50:22 编辑

BOOL CMy0000App::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

CLoginDlg 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
}

// Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.

return FALSE;
}



void CLoginDlg::OnOK() 
{
UpdateData();
CString c_ID,c_code;
m_ID.GetWindowText(c_ID);
m_code.GetWindowText(c_code);
// TODO: Add extra validation here
if (c_ID.IsEmpty()||c_code.IsEmpty())
    {   MessageBox("用户名或密码不能为空");  
return;
        CDialog::OnOK();
}
    if (c_ID=="XCMG_YJY"&&c_code=="123456")
{  AfxGetApp()->m_pMainWnd = NULL; 
   
}
else
{  MessageBox("用户名或密码不正确");
return;
   CDialog::OnOK();
}
}

void CLoginDlg::OnCancel() 
{
// TODO: Add extra cleanup here

CDialog::OnCancel();
}


就只有一步没出来 就是点击确定 没有用 主界面出不来  (其他的输入信息判断都实现了)
[解决办法]
你的主界面是?你说点击确定是指点击“OK”吗
[解决办法]

void CLoginDlg::OnOK() 
{
    UpdateData();
    CString c_ID,c_code;
    m_ID.GetWindowText(c_ID);
    m_code.GetWindowText(c_code);
    // TODO: Add extra validation here
    if (c_ID.IsEmpty()
[解决办法]
c_code.IsEmpty())
    {   
        MessageBox("用户名或密码不能为空");  
        return;
        //CDialog::OnOK();这个貌似不需要吧
    }
    if (c_ID=="XCMG_YJY"&&c_code=="123456")
    {  
        AfxGetApp()->m_pMainWnd = NULL; 
    }
    else
    {  
        MessageBox("用户名或密码不正确");
        return;
    }
    CDialog::OnOK();//从上面的代码块移下来了
}

个人觉得你的这段代码有问题,修改了以下你试试吧,之前回复了你的帖子,没有帮你解决,现在希望能帮到你
[解决办法]

CLoginDlg dlg;
m_pMainWnd = &dlg;
dlg.DoModal();
// 你的主窗口就是 CLoginDlg dlg

CDialog::OnOK();
// 当执行完OnOK()后,你的dlg就结束了,整个程序也结束了,
// 从你的代码来看,根本没有你所说的那个主窗口,只有一个登录窗口

还有,你知道你这一句在干神马么?
AfxGetApp()->m_pMainWnd = NULL; 
你自己都不知道你写的代码啥意思哦,呵呵,我说话比较文明,呵呵,分都给我吧,打这么多字也挺不容易的
[解决办法]
主窗口都被你替换成登录窗口了,如何会显示出来?
[解决办法]
    CLoginDlg dlg;
    m_pMainWnd = &dlg;


    int nResponse = dlg.DoModal();
...
    if (c_ID=="XCMG_YJY"&&c_code=="123456")   
    {  AfxGetApp()->m_pMainWnd = NULL; 
    }

一点疑问m_pMainWnd就是&dlg,何来主窗口?
况且你把m_pMainWnd置NULL作甚?主窗口就可以出来了?

热点排行