5

I have a design like below:

enter image description here

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.

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.

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.

Any help will be appreciated.

Community
  • 1
  • 1
foobar
  • 2,887
  • 2
  • 30
  • 55

3 Answers3

7

What you can do is use a normal CDialog class, add your buttons to it and also create a frame/rect as a placeholder for where your embedded dialogs are to appear. The following piece of code will create and position your embedded dialog.

CRect rect;
CWnd *pHost = GetDlgItem(ID_OF_YOUR_FRAME_RECT);
pHost->GetWindowRect(&rect);
ScreenToClient(&rect);
pDialog->Create(ID_OF_YOUR_DIALOG, this);
pDialog->MoveWindow(&rect);
pDialog->ShowWindow(SW_SHOW);

On button clicks, you hide the previously shown dialog (SW_HIDE) and show your selected dialog(SW_SHOW) with ShowWindow(...).

If you create your embedded dialogs with IDD_FORMVIEW style in the add resource editor it'll have the proper styles for embedding.

Another option is probably to use an embedded PropertySheet and hide the tab row and programatically change the tabs on the button clicks. I just find it to be too much fuzz with borders, positioning, validation and such for my liking.

imbtfab
  • 493
  • 4
  • 10
  • `CWnd *pHost = GetDlgItem(ID_OF_YOUR_FRAME_RECT);` fires the debug assertion as GetDlgItem(ID_OF_YOUR_FRAME_RECT) returns NULL, any idea ? – foobar Apr 01 '14 at 13:15
  • Make sure you have called CDialog::OnInitDialog first – imbtfab Apr 01 '14 at 13:18
  • The comments after the ASSERT will usually say why it triggered, but in any case, post the ASSERT statement here – imbtfab Apr 01 '14 at 14:24
  • This line `ASSERT(::IsWindow(m_hWnd));` inside GetDlgItem() function is causing exception `Unhandled exception at 0x510bcdac (mfc100ud.dll) in Demo.exe: 0xC0000005: Access violation reading location 0x00000020.` – foobar Apr 02 '14 at 06:03
4

If you have the MFC Feature Pack, that first came with VS2008 SP1 and is in all later versions, you might like to consider CMFCPropertySheet. There are a number of examples on the linked page, that are very similar to your design.

For example, this:

example 1

Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
1

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);
foobar
  • 2,887
  • 2
  • 30
  • 55