如何从一个对话框弹出单文档视图
轉(zhuǎn)自:http://blog.csdn.net/clever101/article/details/768515
相信不少人進行數(shù)據(jù)庫編程都有這樣的問題,如何設(shè)置一個登陸框,通過登陸框來進入單文檔視圖。我看到很多數(shù)據(jù)庫編程方面的書,都是對話框之間的相互切換。而在對話框中添加菜單不少人都不太熟悉(當然這是可以辦到的)。我在想:為何不能在對話框中彈出單文檔,這樣添加菜單等工作就方便多了。為此我?guī)捉?jīng)探索,終于實現(xiàn)了如何從一個對話框彈出單文檔視圖。
?
下面我以一個登陸對話框為例來說明如何從一個對話框彈出單文檔視圖。
首先新建一個對話框資源,如下圖:
熟悉MFC編程的朋友都知道初始化程序?qū)嵗怯?span style="font-family:'Times New Roman';">InitInstance函數(shù)完成的。因此彈出這個對話框的代碼也是放在這個函數(shù)里的。
代碼如下:
?
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后就開始初始化程序?qū)嵗?/span> {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 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函數(shù)里添加相應的處理代碼。
m_Time是全局變量,初始值為0. void CLogsys::OnOK() {// TODO: Add extra validation here UpdateData(TRUE); // 獲取輸入數(shù)據(jù) if(m_strUser=="Admin"&&m_strPwd=="1234") { CDialog::OnOK(); // 假如用戶名和密碼正確,就關(guān)閉對話框 } /*假如用戶名或密碼錯誤,且還未超出登陸次數(shù),就進行提示*/ if((m_strUser!="Admin"||m_strPwd!="1234")&&(m_Time<3)) //假如密碼和用戶名正確 { AfxMessageBox("用戶名或密碼不正確"); m_Time++;} /*假如超出登陸次數(shù),提示并退出系統(tǒng)*/ if(m_Time>2){ AfxMessageBox("登陸錯誤次數(shù)超過3次"); PostQuitMessage(0);} }當然在實際中功能還應進行擴充,比如3次登陸失敗后就應限制這臺電腦在一定時間內(nèi)不能登陸等,還有比如如何驗證多個用戶名進行登陸等等。
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/smh2015/p/6518713.html
總結(jié)
以上是生活随笔為你收集整理的如何从一个对话框弹出单文档视图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网络金融产品有哪些 投资者需要注意投资的
- 下一篇: 富满电子生产什么芯片 模拟IC和LED驱