1
votes

I want to build a MFC application, with one main dialog, and all the other dialogs are child of this main dialog (and embedded in it).

Now, i was able to embed the first child in the main dialog, but i want to pass to the next dialog (note that the order of opened dialogs is random), so i need to hide the first dialog and show another. To know which dialog is shown at the moment and hide it, i've tried using a CDialog variable to store the current opened dialog, but i get a CObject::operator =' : cannot access private member declared in class 'CObject' error.

Is there another way to do this "hide and show dialogs" game?

EDIT: Could i store some ID of the dialogs and use it to acomplish this task?

1
Have you subclassed CDialog? Sounds almost as if you haven'tAndersK
You should, then in the main dialog just add a vector with them e.g. std::vector<std::shared_ptr<CDialog>> to keep track of them. Whenever you move from one dialog to another go through the vector and show/hideAndersK
And just subclassing is going to be enough to store dialogs in a vector, or list? Isn't there some method to override or change?MRM
If you at least subclass one dialog you can put in whatever members you want e.g. a vector of dialog pointers. then add a method to create all the dialogs hidden, after that it is just a matter of turning visibility on and off. you haven't explained so much in your question so i am just trying to answer from what you have asked.AndersK
Would a property sheet framework be more appropriate?rrirower

1 Answers

0
votes

So i managed to accomplish this task using classes IDDs.

First, i store the last opened dialog's IDD

m_dlgStartPage.Create(CStartPageDlg::IDD, this);
m_openedWin.nDialogIDD = m_dlgStartPage.IDD;
m_dlgStartPage.ShowWindow(SW_SHOW);

Then, when a new dialog needs to be shown, i send a message to my main dialog (nIDD is the IDD of pending dialog to show):

AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND_CHANGE_WINDOW, nIDD, 0);

And last, in my main dialog, i parse all the child dialogs and check if m_openedWin.nDialogIDD matches with each dialog's IDD, so i can hide it. After this, i parse once again all the chid dialogs and use the nIDD from the sent message to show the correct one.

I don't really like this approach, because of all the parsing and sent messages to the main dialog's class, so if anyone has a better idea or method, please post it.