在单文档程序中,比如有些数据库应用程序,在程序运行时先出现一个用户登陆对话框,如果用户输入的密码正确则进入主界面,否则退出。我看了一下是在 InitInstence函数中加入了这几句:CDialog logindlg;
if(logindlg.Domodal() == IDOK)
{
}
else
{
return FASLE; //退出程序
}我想在基于对话框的程序里也实现这个效果,但是我把那些代码放在InitInstence中,可以通过编译,但是运行就报错。请问大家怎么做,谢谢
if(logindlg.Domodal() == IDOK)
{
}
else
{
return FASLE; //退出程序
}我想在基于对话框的程序里也实现这个效果,但是我把那些代码放在InitInstence中,可以通过编译,但是运行就报错。请问大家怎么做,谢谢
CLoginDlg LoginDlg;
if(LoginDlg.DoModal() == IDOK)
{
CDialogTestDlg 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
}
}
BOOL CSzhrApp::InitInstance()
{
// 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 AfxOleInit(); //初始化 COM 环境 CLogDlg dlg; //你自己的登录对话框
int nResponse = dlg.DoModal();
m_pMainWnd = &dlg;
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
CSzhrDlg dlg; //原程序的对话框
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;
}
你的方法也不行啊
if(logindlg.Domodal() == IDOK) //DoModal()
{
}
else
{
return FASLE; //退出程序
}编译不通过是不因为上面的写错了,对于Single Document 也应该可以吧~关注!
{
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 CNewDlg newdlg;
if (newdlg.DoModal() == IDCANCEL)
{
return FALSE;
} CCTestDlg 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;
}