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();
}
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就结束了,整个程序也结束了,
// 从你的代码来看,根本没有你所说的那个主窗口,只有一个登录窗口
int nResponse = dlg.DoModal();
...
if (c_ID=="XCMG_YJY"&&c_code=="123456")
{ AfxGetApp()->m_pMainWnd = NULL;
}
一点疑问m_pMainWnd就是&dlg,何来主窗口?
况且你把m_pMainWnd置NULL作甚?主窗口就可以出来了?