Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. parent and child data exchange

parent and child data exchange

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helpdiscussion
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L llp00na

    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

    M Offline
    M Offline
    Maxwell Chen
    wrote on last edited by
    #2

    Try sending a message (WM_USER + N) to the child / parent ...


    Maxwell Chen

    L 1 Reply Last reply
    0
    • M Maxwell Chen

      Try sending a message (WM_USER + N) to the child / parent ...


      Maxwell Chen

      L Offline
      L Offline
      llp00na
      wrote on last edited by
      #3

      would you please clarify more.Whats the purpose of the message (WM_USER + N)??? llp00na

      M 1 Reply Last reply
      0
      • L llp00na

        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

        M Offline
        M Offline
        MANISH RASTOGI
        wrote on last edited by
        #4

        reinterpret_cast(AfxGetApp())->xParent = 5;

        1 Reply Last reply
        0
        • L llp00na

          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

          M Offline
          M Offline
          MANISH RASTOGI
          wrote on last edited by
          #5

          //By this you can set the value of parent member variable from child window. reinterpret_cast(AfxGetApp())->xParent = 5; // AnyValue

          L 1 Reply Last reply
          0
          • L llp00na

            would you please clarify more.Whats the purpose of the message (WM_USER + N)??? llp00na

            M Offline
            M Offline
            Maxwell Chen
            wrote on last edited by
            #6

            Please read this[^].


            Maxwell Chen

            1 Reply Last reply
            0
            • L llp00na

              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

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #7

              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 and yChild. 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

              L 1 Reply Last reply
              0
              • D David Crow

                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 and yChild. 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

                L Offline
                L Offline
                llp00na
                wrote on last edited by
                #8

                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

                D 1 Reply Last reply
                0
                • M MANISH RASTOGI

                  //By this you can set the value of parent member variable from child window. reinterpret_cast(AfxGetApp())->xParent = 5; // AnyValue

                  L Offline
                  L Offline
                  llp00na
                  wrote on last edited by
                  #9

                  I tried using this method but its giving me a compilation error llp00na

                  1 Reply Last reply
                  0
                  • L llp00na

                    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

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #10

                    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

                    1 Reply Last reply
                    0
                    • L llp00na

                      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

                      R Offline
                      R Offline
                      Radu Sorin
                      wrote on last edited by
                      #11

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups