在主对话框中嵌入对话框并通过在 MFC 中单击按钮来切换它们

2022-01-12 00:00:00 dialog winapi c++ mfc

我的设计如下:

所以基本上,我想在应用程序主对话框中嵌入三个对话框并在它们之间切换,对于每个按钮单击,即按钮 1 将显示对话框一,按钮 2 将隐藏对话框 1 并显示对话框 2 .. 等等.每个对话框都有不同的设计和功能.

So basically, I want to embed three dialogs in the application main dialog and switch between them, for each button click i.e., button 1 will show dialog one , button 2 will hide dialog 1 and show dialog 2 .. and so on. Each dialog will be having a different design and functions.

我尝试使用 CPropertySheet 类来添加页面,但它的 GUI 不同.它具有使用下一个/后退按钮或从选项卡控件导航对话框的选项.这些都不符合我的要求.

I tried using CPropertySheet class to Add pages but its GUI is different. It has either option for navigating the dialogs using next / back button , or from a tab control. None of which is as per my requirement.

所以我想知道在 MFC 中是否可以有这样的设计?如果是怎么办?我应该使用哪个类/控件.

So I want to know is it possible to have a design like this in MFC ? If yes how? Which Class/ control should I use.

任何帮助将不胜感激.

推荐答案

仅使用基于对话框的应用程序对我有用的是 SetParent() 方法.不知道为什么没有人提到它.它似乎工作正常.我的做法如下:

What worked for me just using dialog based application is SetParent() method. Dont know why nobody mentioned it. It seems to work fine. I am doing like below:

 VERIFY(pDlg1.Create(PanelDlg::IDD, this));
 VERIFY(pDlg2.Create(PanelDlg2::IDD, this));
 VERIFY(pDlg3.Create(PanelDlg2::IDD, this));

   ::SetParent(pDlg1.GetSafeHwnd(), this->m_hWnd);
   ::SetParent(pDlg2.GetSafeHwnd(), this->m_hWnd);
   ::SetParent(pDlg3.GetSafeHwnd(), this->m_hWnd);

现在我可以随意显示或隐藏子对话框(单击按钮),如下所示:

Now I can show or hide a child dialog at will (button clicks) as below:

   pDlg1.ShowWindow(SW_SHOW);
   pDlg2.ShowWindow(SW_HIDE);
   pDlg3.ShowWindow(SW_HIDE);

相关文章