MFC一个父对话框,多个子对话框 [英] MFC one parent dialog, multiple child dialogs
问题描述
我想构建一个MFC应用程序,一个主对话框,所有其他对话框是这个主对话框的子对象(并嵌入其中)。
现在,我可以在主对话框中嵌入第一个子对象,但我想传递到下一个对话框(注意打开的对话框的顺序是随机的) ,所以我需要隐藏第一个对话框并显示另一个。要知道当前显示的对话框并隐藏它,我试着使用 CDialog
变量来存储当前打开的对话框,但我得到一个 CObject :: operator =':无法访问在'CObject'类中声明的私有成员
错误。
隐藏和显示对话框游戏?
编辑:我可以存储对话框的一些ID并使用它来完成此任务吗?
首先,我存储最后打开的对话框的IDD
m_dlgStartPage.Create(CStartPageDlg :: IDD,this);
m_openedWin.nDialogIDD = m_dlgStartPage.IDD;
m_dlgStartPage.ShowWindow(SW_SHOW);
然后,当需要显示一个新对话框时, code> nIDD 是待显示对话框的IDD):
AfxGetApp m_pMainWnd-> SendMessage(WM_COMMAND_CHANGE_WINDOW,nIDD,0);
最后,在我的主对话框中,我解析所有的子对话框检查 m_openedWin.nDialogIDD
是否与每个对话框的IDD匹配,所以我可以隐藏它。之后,我再次解析所有的chid对话框,并使用发送的消息中的 nIDD
显示正确的对话框。
我不喜欢这种方法,因为所有的解析和发送消息到主对话框的类,所以如果任何人有一个更好的主意或方法,请张贴。
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?
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.
这篇关于MFC一个父对话框,多个子对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!