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. Communication between classes

Communication between classes

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorialannouncement
6 Posts 4 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.
  • K Offline
    K Offline
    Kamis
    wrote on last edited by
    #1

    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?

    D R K 3 Replies Last reply
    0
    • K Kamis

      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?

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

      Something like:

      CMainDlg::OnButtonClick()
      {
      CChildDlg dlg(&some_data_here); // pass a pointer to the data that
      // CChildDlg can modify directly

      if (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

      T 1 Reply Last reply
      0
      • K Kamis

        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?

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • K Kamis

          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?

          K Offline
          K Offline
          Kamis
          wrote on last edited by
          #4

          Thanks

          1 Reply Last reply
          0
          • D David Crow

            Something like:

            CMainDlg::OnButtonClick()
            {
            CChildDlg dlg(&some_data_here); // pass a pointer to the data that
            // CChildDlg can modify directly

            if (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

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • T toxcct

              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

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

              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 access CChildDlg 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

              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