MFC如何在单文档中添加对话框

曾经看过一个程序,运行时打开一个单文档,单文档的最右边连着一个对话框,但我不知道怎么实现,请高手详细解说下。那个程序被我删了,本来想找出来参考的......T.T他是用M... 曾经看过一个程序,运行时打开一个单文档,单文档的最右边连着一个对话框,但我不知道怎么实现,请高手详细解说下。那个程序被我删了,本来想找出来参考的......T.T
他是用MFC做的界面!
展开
 我来答
可以叫我表哥
2015-08-13 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
采纳数:25898 获赞数:1464928
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。

向TA提问 私信TA
展开全部
  首先新建一个对话框资源,初始化程序实例是由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<3)) //假如密码和用户名正确
   {
  AfxMessageBox("用户名或密码不正确");
  m_Time++;
   }
  /*假如超出登陆次数,提示并退出系统*/
  if(m_Time>2)
   {
  AfxMessageBox("登陆错误次数超过3次");
  PostQuitMessage(0);
   }
  }
  当然在实际中功能还应进行扩充,比如3次登陆失败后就应限制这台电脑在一定时间内不能登陆等,还有比如如何验证多个用户名进行登陆等等。
stone_dongdong
2009-01-09 · TA获得超过2851个赞
知道大有可为答主
回答量:1636
采纳率:0%
帮助的人:952万
展开全部
哪个是具有 ws_child属性的对话框。
在VC资源管理器里面和平常的对话框一样设计,只要在其属性里面修改为child 就行了。

实现方法有很多,
1.嵌入在CToolBar里面,
2.CreateClient的时候划分尺寸,将缩小原本留给view的尺寸,给那个对话框预留空间。
具体实现起来步骤可能不一样,但大同小异。
其实就用对话框模式创建工程,添加RichEdit可以实现和sdi/mdi一样的效果。

sdi/mdi架构过于繁琐,ms定义了太多不相干或许永远也用不到的方法
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
魔高丈
2009-01-08 · TA获得超过9505个赞
知道大有可为答主
回答量:2066
采纳率:0%
帮助的人:3348万
展开全部
连着一个对话框,不知道怎么个连法?是在主程序框架的里面,还是在外面?这个对话框有标题条和边框吗?

如果在主框架的里面且没有标题条和边框,那它不是一个对话框,这种效果可以使用CFormView类,或者分割窗口来实现。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式