parent and child data exchange
-
Dear all, I have a simple problem, i hope to get your valuable opinions on it. Okey, so i have built an MFC application. The main application has a modeless child dialog that is only created when a menu item is clicked. the modeless child dialog has edit controls which receive input from the user. Now, user input will be used to modify some global variables in the parent class to be used for some purposes. Let's assume the parent class has the following global variables : xParent, yParent. the modeless child dialog has two edit controls and one button "Set". the two edit controls save the input to xChild and yChild. When the user clicks "Set", the variables of the parent [xParent, yParent] should be set to [xChild, yChild] respectively. How can i do that ? I am thinking to declare an instance of the parent class within the child class and modify the parents variable within the click event of the "Set" button. Do you think its the best approach to solve this problem ? :doh: Thanx llp00na
Try sending a message (WM_USER + N) to the child / parent ...
Maxwell Chen
-
Try sending a message (WM_USER + N) to the child / parent ...
Maxwell Chen
-
Dear all, I have a simple problem, i hope to get your valuable opinions on it. Okey, so i have built an MFC application. The main application has a modeless child dialog that is only created when a menu item is clicked. the modeless child dialog has edit controls which receive input from the user. Now, user input will be used to modify some global variables in the parent class to be used for some purposes. Let's assume the parent class has the following global variables : xParent, yParent. the modeless child dialog has two edit controls and one button "Set". the two edit controls save the input to xChild and yChild. When the user clicks "Set", the variables of the parent [xParent, yParent] should be set to [xChild, yChild] respectively. How can i do that ? I am thinking to declare an instance of the parent class within the child class and modify the parents variable within the click event of the "Set" button. Do you think its the best approach to solve this problem ? :doh: Thanx llp00na
reinterpret_cast(AfxGetApp())->xParent = 5;
-
Dear all, I have a simple problem, i hope to get your valuable opinions on it. Okey, so i have built an MFC application. The main application has a modeless child dialog that is only created when a menu item is clicked. the modeless child dialog has edit controls which receive input from the user. Now, user input will be used to modify some global variables in the parent class to be used for some purposes. Let's assume the parent class has the following global variables : xParent, yParent. the modeless child dialog has two edit controls and one button "Set". the two edit controls save the input to xChild and yChild. When the user clicks "Set", the variables of the parent [xParent, yParent] should be set to [xChild, yChild] respectively. How can i do that ? I am thinking to declare an instance of the parent class within the child class and modify the parents variable within the click event of the "Set" button. Do you think its the best approach to solve this problem ? :doh: Thanx llp00na
//By this you can set the value of parent member variable from child window. reinterpret_cast(AfxGetApp())->xParent = 5; // AnyValue
-
Dear all, I have a simple problem, i hope to get your valuable opinions on it. Okey, so i have built an MFC application. The main application has a modeless child dialog that is only created when a menu item is clicked. the modeless child dialog has edit controls which receive input from the user. Now, user input will be used to modify some global variables in the parent class to be used for some purposes. Let's assume the parent class has the following global variables : xParent, yParent. the modeless child dialog has two edit controls and one button "Set". the two edit controls save the input to xChild and yChild. When the user clicks "Set", the variables of the parent [xParent, yParent] should be set to [xChild, yChild] respectively. How can i do that ? I am thinking to declare an instance of the parent class within the child class and modify the parents variable within the click event of the "Set" button. Do you think its the best approach to solve this problem ? :doh: Thanx llp00na
llp00na wrote:
When the user clicks "Set", the variables of the parent [xParent, yParent] should be set to [xChild, yChild] respectively.
The child will need two variables to hold the values of
xChild
andyChild
. These variables will exist even after the modeless child dialog is dismissed. The parent can access them whenever it needs to.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
llp00na wrote:
When the user clicks "Set", the variables of the parent [xParent, yParent] should be set to [xChild, yChild] respectively.
The child will need two variables to hold the values of
xChild
andyChild
. These variables will exist even after the modeless child dialog is dismissed. The parent can access them whenever it needs to.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
yes, but i wana set the parent's variables within the "Set" button's click event in the child dialog. How do i do that ? The question really, is how to access the parent's variables from the child dialog !!! llp00na -- modified at 10:19 Monday 17th April, 2006
-
//By this you can set the value of parent member variable from child window. reinterpret_cast(AfxGetApp())->xParent = 5; // AnyValue
-
yes, but i wana set the parent's variables within the "Set" button's click event in the child dialog. How do i do that ? The question really, is how to access the parent's variables from the child dialog !!! llp00na -- modified at 10:19 Monday 17th April, 2006
llp00na wrote:
The question really, is how to access the parent's variables from the child dialog !!!
You don't. This is very bad OO practice. For example, if I want to access something in your home, I don't just help myself to it. I send you the proper message and you then get it for me. Read each of these for a better understanding of what you are looking for: http://flounder.com/badprogram.htm[^] http://flounder.com/dlgctl.htm[^]
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
Dear all, I have a simple problem, i hope to get your valuable opinions on it. Okey, so i have built an MFC application. The main application has a modeless child dialog that is only created when a menu item is clicked. the modeless child dialog has edit controls which receive input from the user. Now, user input will be used to modify some global variables in the parent class to be used for some purposes. Let's assume the parent class has the following global variables : xParent, yParent. the modeless child dialog has two edit controls and one button "Set". the two edit controls save the input to xChild and yChild. When the user clicks "Set", the variables of the parent [xParent, yParent] should be set to [xChild, yChild] respectively. How can i do that ? I am thinking to declare an instance of the parent class within the child class and modify the parents variable within the click event of the "Set" button. Do you think its the best approach to solve this problem ? :doh: Thanx llp00na
put two pointers in the child dialog class, that will poin to xParent, yParent (lets say pXParent,pYParent).. Before calling the child dialog initialize them with the address of the xParent, yParent something like childDlg.pXParent = &xParent; childDlg.pYParent = &yParent; childDlg.DoModal(); In childDlg class in the onSet(or whatever name you have for the pushing of the Set button) out something like this *pXParent = xChild; *pYParent = yChild; .... now the xParent,yParent will have the values of xChild, yChild