这是我的登陆窗口类的else分支
其功能为打开主界面,由于我的主界面是在CClientView里面画的
所以这里需要调用CClientView的OnInitialUpdate()函数
但不知道是不是这样而引起的错误
//如果密码输入正确,则打开主界面
else
{
//直接就是这句过不去,然后程序马上就死掉了
CClientView* pView=(CClientView*)((CMainFrame*)AfxGetApp()->m_pMainWnd)->GetActiveView(); pView->OnInitialUpdate();
CDialog::OnOK();
}
若再在else里面再调用时,则会出现资源重复创建等内存泄漏情况,所以程序就死掉了。
CClientView* pView=(CClientView*)((CMainFrame*)AfxGetApp()->m_pMainWnd)->GetActiveView();
哪个指针无效。
m_pMainWnd->ShowWindow(SW_MAXIMIZE);
m_pMainWnd->UpdateWindow();
我是在 CWinApp::InitInstance() 中显示登陆窗口的啊
但是有个登陆时的"确定"按钮 我是做在登陆的类里面的
所以在点击"确定"时 需要我说的那个else语句
我现在不用执行OnInitialUpdate()了 之前的想法不太合理
现在关键是我用了
m_pMainWnd->ShowWindow(SW_MAXIMIZE);
m_pMainWnd->UpdateWindow();
程序界面出不来 只是闪一下就完了 这是怎么回事呢??
if (IDOK != CLoginDialog.DoModal())
return FALSE;m_pMainWnd->ShowWindow(SW_MAXIMIZE);
m_pMainWnd->UpdateWindow();
我也是这样做的
只是实现没有放在 CWinAPP里面
我是在我的CLoginDialog类里面实现的
就出现了我说的那种 只是闪一下的问题 而没有出现窗口
m_pMainWnd->UpdateWindow();return TRUE;
这个我知道,我是在 CLoginDialog::OnOk()
里面去响应"确定"的 并没有在CWinApp里面去做.
CWnd* m_pMainWnd=((CMainFrame*)AfxGetApp()->m_pMainWnd);
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
CDialog::OnOK();能运行到m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
只是看到窗口闪了一下 然后就消失了....
谢谢你的耐心啊
LWX300
//////////////////这是我的CLoginDlg的OnOk/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CLoginDlg::OnOK()
{ // TODO: Add extra validation here
CPswdSet* m_recordset=new CPswdSet(&m_database);
CString strSQL;
UpdateData(TRUE);//读入用户输入的密码
strSQL.Format("select * from password where PASSWORD='%s'",m_password);
m_recordset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);//从数据库中查找,输入的密码是否正确
if(m_recordset->GetRecordCount()==0)
{
if(count<3)
{
MessageBox("口令错误!","提示",MB_OK|MB_ICONINFORMATION);
count++;//登录次数加1
m_password.Empty();
m_ctrlpassword.SetFocus();
UpdateData(FALSE);
}
else
{
MessageBox("你无权使用此系统!","警告",MB_OK|MB_ICONHAND);
m_database.Close();//关闭数据库
CDialog::OnOK();//关闭对话框
}
}
//如果登录成功,则打开主界面
else
{
CWnd* m_pMainWnd=((CMainFrame*)AfxGetApp()->m_pMainWnd);
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
CDialog::OnOK();
}}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////这是我的CWinApp////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////BOOL CWinApp::InitInstance()
{
CAddressDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
return FALSE; 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 // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CClientDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CClientView));
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_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
return TRUE;
*/}
//晕这个才是对的......
//说明一下我的CLoginDlg为CAddressDlg..怕大家看不明白 所以说明一下
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////这是我的CAddressDlg/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void CAddressDlg::OnOK()
{ // TODO: Add extra validation here
CPswdSet* m_recordset=new CPswdSet(&m_database);
CString strSQL;
UpdateData(TRUE);//读入用户输入的密码
strSQL.Format("select * from password where PASSWORD='%s'",m_password);
m_recordset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);//从数据库中查找,输入的密码是否正确
if(m_recordset->GetRecordCount()==0)
{
if(count<3)
{
MessageBox("口令错误!","提示",MB_OK|MB_ICONINFORMATION);
count++;//登录次数加1
m_password.Empty();
m_ctrlpassword.SetFocus();
UpdateData(FALSE);
}
else
{
MessageBox("你无权使用此系统!","警告",MB_OK|MB_ICONHAND);
m_database.Close();//关闭数据库
CDialog::OnOK();//关闭对话框
}
}
//如果登录成功,则打开主界面
else
{
CWnd* m_pMainWnd=((CMainFrame*)AfxGetApp()->m_pMainWnd);
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
CDialog::OnOK();
}}
///////////////////////////////////////////////////////////////////////////////////////////
////////////这是我的CWinApp////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////BOOL CClientApp::InitInstance()
{
CAddressDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
return FALSE; 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 // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CClientDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CClientView));
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_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
return TRUE;
*/}
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
return FALSE; //InitInstance 返回 FALSE,程序直接退出了。
{
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 // Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CClientDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CClientView));
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.
CAddressDlg dlg;
if (IDOK != dlg.DoModal())
return FALSE; m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
return TRUE;
}void CAddressDlg::OnOK()
{ if(m_recordset->GetRecordCount()==0)
{
if(count<3)
{
...
return;
}
else
{
...
CDialog::OnCancel();//关闭对话框
}
}
//如果登录成功,则打开主界面
CDialog::OnOK();
}
{ if(m_recordset->GetRecordCount()==0)
{
if(count <3)
{
...
return;
}
else
{
...
CDialog::OnCancel();//关闭对话框
return; //再加上这句。
}
}
//如果登录成功,则打开主界面
CDialog::OnOK();
}
还在调呢 不过界面窗口跟登陆窗口是一起出来的哦 有点BUG
BOOL CClientApp::InitInstance()
{
CAddressDlg dlg;
if (IDOK != dlg.DoModal())
return FALSE; //这里用于返回假,使窗口不能打开 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
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CClientDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CClientView));
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_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
return TRUE;
}