Communication between classes
-
Situation is quite ordinary: I have a main window class(for example derived from CDialog) and call a modal dialog from it's method. Choosing some settings from within it affects data of the main window class. So what is the most elegant way to establish communication between these two dialogs? How is it implemented more often in practice? One solution I see is to pass a pointer of the main class as an argument to constructor or any other method of this "settings" dialog and manipulate all tha data directly. Or I can save all changes in some kind of mediums such as global variables or object with static members and then when this secondary dialog is about to be destroyed it sends message to the main window class in order to read data from these transitional variables and update it's data. Or perhaps there is another way to do it?
-
Situation is quite ordinary: I have a main window class(for example derived from CDialog) and call a modal dialog from it's method. Choosing some settings from within it affects data of the main window class. So what is the most elegant way to establish communication between these two dialogs? How is it implemented more often in practice? One solution I see is to pass a pointer of the main class as an argument to constructor or any other method of this "settings" dialog and manipulate all tha data directly. Or I can save all changes in some kind of mediums such as global variables or object with static members and then when this secondary dialog is about to be destroyed it sends message to the main window class in order to read data from these transitional variables and update it's data. Or perhaps there is another way to do it?
Something like:
CMainDlg::OnButtonClick()
{
CChildDlg dlg(&some_data_here); // pass a pointer to the data that
// CChildDlg can modify directlyif (dlg.DoModal() == IDOK) ...
}
If you don't want to do it via the constructor, try:
CMainDlg::OnButtonClick()
{
CChildDlg dlg;dlg.m\_some\_data = m\_some\_data; if (dlg.DoModal() == IDOK) m\_some\_data = dlg.m\_some\_data;
}
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
-
Situation is quite ordinary: I have a main window class(for example derived from CDialog) and call a modal dialog from it's method. Choosing some settings from within it affects data of the main window class. So what is the most elegant way to establish communication between these two dialogs? How is it implemented more often in practice? One solution I see is to pass a pointer of the main class as an argument to constructor or any other method of this "settings" dialog and manipulate all tha data directly. Or I can save all changes in some kind of mediums such as global variables or object with static members and then when this secondary dialog is about to be destroyed it sends message to the main window class in order to read data from these transitional variables and update it's data. Or perhaps there is another way to do it?
Imho, the most elegant way would be to package your data in an object that exists in your main window, and pass that object to the modal dialog. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
-
Situation is quite ordinary: I have a main window class(for example derived from CDialog) and call a modal dialog from it's method. Choosing some settings from within it affects data of the main window class. So what is the most elegant way to establish communication between these two dialogs? How is it implemented more often in practice? One solution I see is to pass a pointer of the main class as an argument to constructor or any other method of this "settings" dialog and manipulate all tha data directly. Or I can save all changes in some kind of mediums such as global variables or object with static members and then when this secondary dialog is about to be destroyed it sends message to the main window class in order to read data from these transitional variables and update it's data. Or perhaps there is another way to do it?
-
Something like:
CMainDlg::OnButtonClick()
{
CChildDlg dlg(&some_data_here); // pass a pointer to the data that
// CChildDlg can modify directlyif (dlg.DoModal() == IDOK) ...
}
If you don't want to do it via the constructor, try:
CMainDlg::OnButtonClick()
{
CChildDlg dlg;dlg.m\_some\_data = m\_some\_data; if (dlg.DoModal() == IDOK) m\_some\_data = dlg.m\_some\_data;
}
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
ok, but, if we do the second method, you consider that DoModal() returns IDOK before destroying the CChildDlg . Don't DoModal() return it value when the dialog's closed ? what about passing to the CChildDlg directly a pointer to the "parent dialog" instead of a pointer to a some data ? thx for your answer
TOXCCT >>> GEII power
-
ok, but, if we do the second method, you consider that DoModal() returns IDOK before destroying the CChildDlg . Don't DoModal() return it value when the dialog's closed ? what about passing to the CChildDlg directly a pointer to the "parent dialog" instead of a pointer to a some data ? thx for your answer
TOXCCT >>> GEII power
toxcct wrote: DoModal() returns IDOK before destroying the CChildDlg . Don't DoModal() return it value when the dialog's closed ? The
CChildDlg
object exists after the dialog it was associated with has been destroyed. This is why you can accessCChildDlg
member variables after the dialog has been dismissed.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow