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. two dialogs, global variables? (vc++ 6.0 mfc)

two dialogs, global variables? (vc++ 6.0 mfc)

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
6 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.
  • R Offline
    R Offline
    rolfhorror
    wrote on last edited by
    #1

    i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks

    T D H M 4 Replies Last reply
    0
    • R rolfhorror

      i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks

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

      guess what, i've just submitted a new article about that (around last thursday), but i'm still waiting for it to be published (editors have a lot of work)... when it comes out, don't hesitate to check it (called Dialogs Communication - Or the art of exchanging data...). for your input, transmit your infos thru the child dialog's constructor


      [VisualCalc][Flags Beginner's Guide] | [Forums Guidelines][My Best Advice]

      1 Reply Last reply
      0
      • R rolfhorror

        i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks

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

        rolfhorror wrote:

        how can these two dialogs share variables?

        Do they really need to? If so, they are inherently tied together from that point forward. That's not necessarily a bad thing, but it does keep the child dialog from being re-used. Several solutions exist:

        void CMainDialog::SomeAction()
        {
        CChildDialog dlg(m_var1, m_var2);
        // or
        dlg.m_var1 = m_var1;
        dlg.m_var2 = m_var2;
        // or
        dlg.SetVar1(m_var1);
        dlg.SetVar2(m_var2);

        if (dlg.DoModal() == IDOK)
        {
            m\_var1 = dlg.m\_var1;
            m\_var2 = dlg.m\_var2;
            // or
            m\_var1 = dlg.GetVar1();
            m\_var2 = dlg.GetVar2();
        }
        

        }


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        1 Reply Last reply
        0
        • R rolfhorror

          i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Is this helpfuls you can insert this code to child dialog after user insert his text on your editbox. After insert text to editbox on the child dialog you can get this string and use of this code (if you dont need to global cstring)

          CMain *m_Main=(CMain*)GetParent();
          m_Main->m_EditControl.SetWindowText();


          WhiteSky


          1 Reply Last reply
          0
          • R rolfhorror

            i have two dialogs, one main and one child. i'd like to get userinput in the childs editctrls and then pass them on to the main dialogs editctrls through global cstring variables. how can these two dialogs share variables? thanks

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            one solution is to pass a pointer (this) of the parent dialog to the child dialog :

            //...
            MyChildDialog dlg( this );
            dlg.DoModal();

            But that would force a "coupling" dependance between both dialogs; maybe it's ok for your particular situation.


            Maximilien Lincourt Your Head A Splode - Strong Bad

            R 1 Reply Last reply
            0
            • M Maximilien

              one solution is to pass a pointer (this) of the parent dialog to the child dialog :

              //...
              MyChildDialog dlg( this );
              dlg.DoModal();

              But that would force a "coupling" dependance between both dialogs; maybe it's ok for your particular situation.


              Maximilien Lincourt Your Head A Splode - Strong Bad

              R Offline
              R Offline
              rolfhorror
              wrote on last edited by
              #6

              thanks alot guys, i'll try your coding.

              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