如何从一个对话框弹出单文档视图 | 您所在的位置:网站首页 › 16万泰铢等于多少人民币 › 如何从一个对话框弹出单文档视图 |
熟悉MFC编程的朋友都知道初始化程序实例是由InitInstance函数完成的。因此弹出这个对话框的代码也是放在这个函数里的。 代码如下:
BOOL CDlgTestApp::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
// 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.
CLogsys TestDlg; if(TestDlg.DoModal()==IDOK) // 单击Ok后就开始初始化程序实例 { CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CDlgTestDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CDlgTestView)); 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_SHOW); m_pMainWnd->UpdateWindow(); return TRUE; } else // 假如单击了CANCEL按钮就直接退出 return FALSE;
}
当然不是单击OK就可以进入单文档视图,在单击OK后还要进行检查用户名和密码。因此要在对话框的OnOK函数里添加相应的处理代码。 void CLogsys::OnOK() { // TODO: Add extra validation here UpdateData(TRUE); // 获取输入数据 if(m_strUser=="Admin"&&m_strPwd=="1234") { CDialog::OnOK(); // 假如用户名和密码正确,就关闭对话框 } /*假如用户名或密码错误,且还未超出登陆次数,就进行提示*/ if((m_strUser!="Admin"||m_strPwd!="1234")&&(m_Time AfxMessageBox("登陆错误次数超过3次"); PostQuitMessage(0); } }
当然在实际中功能还应进行扩充,比如3次登陆失败后就应限制这台电脑在一定时间内不能登陆等,还有比如如何验证多个用户名进行登陆等等。
|
CopyRight 2018-2019 实验室设备网 版权所有 |