如何在 MFC 应用程序中动态创建对话框?

How to create a dialog box dynamically in MFC application?

我正在开发 MFC SDI 应用程序。我想在单击菜单按钮时调用一个对话框,但我想动态创建该对话框而不使用资源视图。即使在谷歌搜索了很多之后,我也不知道该怎么做。

  • 创建空对话框资源或使用内存中的空资源模板。
  • 创建对话框。使用指向内存中或资源中资源模板的指针。
  • 调用 DoModal。
  • 在 OnInitDialog 中。调整对话框大小,创建所有 child windows,设置对话框标题...

大约在 Visual Studio 2008 年,VS2005 示例页面上有一些名为 DLGTEMPL. I've used it to build a dynamic dialog just like you want. I'm using VS2013 and I could not seem to find the sample code on my local hard drive. However, Microsoft still makes this available here 的示例代码。只需单击顶部的 "Download Sample",它就会将示例安装到您的硬盘上。该示例为从内存资源创建动态对话框提供了基础。