深入分析:怎样从一个对话框弹出单文档视图
来源:互联网 发布:g1 4内螺纹编程 编辑:程序博客网 时间:2024/04/27 16:45
深入分析:怎样从一个对话框弹出单文档视图
据库频道
数据库编程问题:如何设置一个登陆框,通过登陆框来进入单文档视图。
一般情况下采用的方法大多都是对话框之间的相互切换。但在对话框中添加菜单很多人都特别的陌生。下面我们来介绍一个在对话框中弹出单文档的方法,掌握这个方法之后添加菜单等工作就会容易的很多。
本文中我们将以一个登陆对话框为示例,详细的介绍如何从一个对话框弹出单文档视图。
首先我们需要新建一个对话框资源,以下为一个简单的示例:
User □Password □OK Cancel
注释:初始化程序实例是由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#elseEnable3dControlsStatic(); // 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 windowRUNTIME_CLASS(CDlgTestView));AddDocTemplate(pDocTemplate);// Parse command line for standard shell commands, DDE, file openCCommandLineInfo cmdInfo;ParseCommandLine(cmdInfo);// Dispatch commands specified on the command lineif (!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<3)) //如果密码和用户名正确 {AfxMessageBox(”用户名或密码不正确”);m_Time++; }/*如果超出登陆次数,提示并退出系统*/if(m_Time>2) {AfxMessageBox(”登陆错误次数超过3次”);PostQuitMessage(0); }}
总结:在实际中这些功能还应进行相应的扩充,例如3次登陆失败后就应限制这台电脑在一定时间内不能登陆等,另外还要留意如何验证多个用户名进行登陆等其他相关问题。
- 深入分析:怎样从一个对话框弹出单文档视图
- 如何从一个对话框弹出单文档视图
- 如何从一个对话框弹出单文档视图
- 如何从一个对话框弹出单文档视图
- 一个单文档应用程序,怎样实现“打开时,弹出一个对话框,而不是单文档”
- 怎样弹出一个输入对话框
- 怎样看出一个MFC是基于对话框还是多文档或者单文档?
- VC单文档点击菜单弹出对话框
- 在单文档视图中加入对话框
- 深入分析MFC文档视图
- 【交互】单文档多视图代码分析
- 深入分析MFC文档视图结构
- 深入分析MFC文档视图结构
- 深入分析MFC文档视图结构
- 深入分析MFC文档视图结构
- 深入分析MFC文档视图结构
- 深入分析MFC文档视图结构
- 深入分析MFC文档视图结构
- 解决头文件相互包含问题的方法
- 在.Net中使用AnyChart的简单例子(上)
- 程序员-上路吧
- eclipse字符集设置问题
- Vim Shortcut
- 深入分析:怎样从一个对话框弹出单文档视图
- JAVA调用exe可执行文件
- 俞黎敏与JAVA脚本编程
- 认真做事_好好做人
- 面对火灾怎么办?
- 百度空间模板CSS全攻略
- 一种不安装JRE环境即可运行Java应用程序的方法
- InfoQ 数据库架构采访文字修正稿
- asp.net遍历控件