如何从一个对话框弹出单文档视图
来源:互联网 发布:使用手册制作软件 编辑:程序博客网 时间:2024/04/27 14:28
原文地址:http://blog.csdn.net/clever101/article/details/768515
朱金灿
相信不少人进行数据库编程都有这样的问题,如何设置一个登陆框,通过登陆框来进入单文档视图。我看到很多数据库编程方面的书,都是对话框之间的相互切换。而在对话框中添加菜单不少人都不太熟悉(当然这是可以办到的)。我在想:为何不能在对话框中弹出单文档,这样添加菜单等工作就方便多了。为此我几经探索,终于实现了如何从一个对话框弹出单文档视图。
下面我以一个登陆对话框为例来说明如何从一个对话框弹出单文档视图。
首先新建一个对话框资源,如下图:
熟悉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 _AFXDLLEnable3dControls(); // 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次登陆失败后就应限制这台电脑在一定时间内不能登陆等,还有比如如何验证多个用户名进行登陆等等。
- 如何从一个对话框弹出单文档视图
- 如何从一个对话框弹出单文档视图
- 如何从一个对话框弹出单文档视图
- 深入分析:怎样从一个对话框弹出单文档视图
- 一个单文档应用程序,怎样实现“打开时,弹出一个对话框,而不是单文档”
- VC单文档点击菜单弹出对话框
- 在单文档视图中加入对话框
- 如何实现单文档多视图?
- JavaScript 如何弹出一个对话框窗口
- 单文档视图中如何获得视图指针
- 如何让主对话框启动时弹出一个对话框
- 4.3--对话框如何访问活动文档(或视图)对象?
- 单文档视图分割
- 单文档视图切分
- 单文档多视图
- 单文档视图应用程序
- 制作一个BCG单文档模拟的对话框
- 单文档、多文档、对话框
- 微软测试管理运行Coded UI Test
- make: 1254-055 Dependency line needs colon or double colon operator.
- 慎用CMFCToolBar::CreateEx(转的)
- 分布式Coded UI Tests测试
- C#中dataGridView显示时折叠与展开(隐藏与显示)
- 如何从一个对话框弹出单文档视图
- S3C2440对Nand Flash操作和电路原理(基于K9F2G08U0A)
- UINCODE环境下编写剪贴板程序代码
- eclipse 控制台输出ibatislog
- 创建与调用以axis实现的stub方式webservice服务
- org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file
- ERROR: unknown option journal
- Visual Studio 2010自动化Web应用测试实践
- MFC中Picture Control如何添加图片