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. accessing parent variables from dialog mfc??

accessing parent variables from dialog mfc??

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
14 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.
  • D David Crow

    bimgot wrote:

    ...it just does nothing...

    Which means "nothing" without any supporting data. Does GetParent() return the correct parent address? How about a snippet of code that shows what does not work?


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

    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

    B Offline
    B Offline
    bimgot
    wrote on last edited by
    #5

    OnTimer in the dialog class: void CDlg::OnTimer(UINT_PTR nIDEvent) { CDialog::OnTimer(nIDEvent); dlg_level = dlg_sldr.GetPos(); CformView* form = (CformView*) GetParent(); form->form_level = dlg_level; form->UpdateData(TRUE); UpdateData(TRUE); } then from form view class: void CformView::OnViewDlg() { CDlg dialog; dialog.dlg_level = form_sldr.GetPos(); dialog.DoModal(); } hope this makes sense

    J D 2 Replies Last reply
    0
    • B bimgot

      OnTimer in the dialog class: void CDlg::OnTimer(UINT_PTR nIDEvent) { CDialog::OnTimer(nIDEvent); dlg_level = dlg_sldr.GetPos(); CformView* form = (CformView*) GetParent(); form->form_level = dlg_level; form->UpdateData(TRUE); UpdateData(TRUE); } then from form view class: void CformView::OnViewDlg() { CDlg dialog; dialog.dlg_level = form_sldr.GetPos(); dialog.DoModal(); } hope this makes sense

      J Offline
      J Offline
      JudyL_MD
      wrote on last edited by
      #6

      UpdateData (TRUE) puts the values currently in the controls into the variables. You need to call UpdateData (FALSE) to move the variable values into the screen controls. Note that I have added a line. This is so that if you have other controls on the screen, you won't lose the values the user might have changed on the screen when you call UpdateData (FALSE).

      void CDlg::OnTimer(UINT_PTR nIDEvent)
      {
      CDialog::OnTimer(nIDEvent);
      dlg_level = dlg_sldr.GetPos();

      CformView* form = (CformView*) GetParent();
      UpdateData (TRUE);
      form->form_level = dlg_level;
      form->UpdateData(FALSE);

      UpdateData(TRUE);
      }

      Judy

      D B 2 Replies Last reply
      0
      • J JudyL_MD

        UpdateData (TRUE) puts the values currently in the controls into the variables. You need to call UpdateData (FALSE) to move the variable values into the screen controls. Note that I have added a line. This is so that if you have other controls on the screen, you won't lose the values the user might have changed on the screen when you call UpdateData (FALSE).

        void CDlg::OnTimer(UINT_PTR nIDEvent)
        {
        CDialog::OnTimer(nIDEvent);
        dlg_level = dlg_sldr.GetPos();

        CformView* form = (CformView*) GetParent();
        UpdateData (TRUE);
        form->form_level = dlg_level;
        form->UpdateData(FALSE);

        UpdateData(TRUE);
        }

        Judy

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

        JudyL_FL wrote:

        UpdateData (TRUE) puts the values currently in the controls into the variables. You need to call UpdateData (FALSE) to move the variable values into the screen controls.

        All the more reason why UpdateData() should rarely, if ever, be used.


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

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        1 Reply Last reply
        0
        • B bimgot

          OnTimer in the dialog class: void CDlg::OnTimer(UINT_PTR nIDEvent) { CDialog::OnTimer(nIDEvent); dlg_level = dlg_sldr.GetPos(); CformView* form = (CformView*) GetParent(); form->form_level = dlg_level; form->UpdateData(TRUE); UpdateData(TRUE); } then from form view class: void CformView::OnViewDlg() { CDlg dialog; dialog.dlg_level = form_sldr.GetPos(); dialog.DoModal(); } hope this makes sense

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

          How does this answer the question, "Does GetParent() return the correct parent address?"

          void CDlg::OnTimer(UINT_PTR nIDEvent)
          {
          CDialog::OnTimer(nIDEvent);
          dlg_level = dlg_sldr.GetPos();

          CformView\* form = (CformView\*) GetParent();
          // what is the value of 'form' here?
          form->form\_level = dlg\_level;
          form->UpdateData(TRUE);
          
          UpdateData(TRUE);
          

          }

          void CformView::OnViewDlg()
          {
          CDlg dialog;
          // what is the value of the 'this' pointer here?
          dialog.dlg_level = form_sldr.GetPos();
          dialog.DoModal();
          }

          Since CDlg is a modal dialog, I question whether this will even work, since messages sent to its parent will be blocked until DoModal() returns.


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

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          B 1 Reply Last reply
          0
          • J JudyL_MD

            UpdateData (TRUE) puts the values currently in the controls into the variables. You need to call UpdateData (FALSE) to move the variable values into the screen controls. Note that I have added a line. This is so that if you have other controls on the screen, you won't lose the values the user might have changed on the screen when you call UpdateData (FALSE).

            void CDlg::OnTimer(UINT_PTR nIDEvent)
            {
            CDialog::OnTimer(nIDEvent);
            dlg_level = dlg_sldr.GetPos();

            CformView* form = (CformView*) GetParent();
            UpdateData (TRUE);
            form->form_level = dlg_level;
            form->UpdateData(FALSE);

            UpdateData(TRUE);
            }

            Judy

            B Offline
            B Offline
            bimgot
            wrote on last edited by
            #9

            thanks very much, i understand UpdateData a bit more now, i think i must have initialised something incorrectly, this still doesnt seem to update the values in the form.. the pointer to the main form is working correctly, if i call something like form->CloseWindow() during OnTimer it works.. i'm using OnTimer() in the main form to actually call the function which sets the volume: void CformView::OnTimer(UINT_PTR nIDEvent) { CFormView::OnTimer(nIDEvent); SetVolume(form_level); UpdateData(FALSE); } would this still get called during the life of the dialog or do i need to set the volume somewhere else? also is it possible some of the properties of the dialog could be effecting things?? really racking my brain here.. thanks

            1 Reply Last reply
            0
            • D David Crow

              How does this answer the question, "Does GetParent() return the correct parent address?"

              void CDlg::OnTimer(UINT_PTR nIDEvent)
              {
              CDialog::OnTimer(nIDEvent);
              dlg_level = dlg_sldr.GetPos();

              CformView\* form = (CformView\*) GetParent();
              // what is the value of 'form' here?
              form->form\_level = dlg\_level;
              form->UpdateData(TRUE);
              
              UpdateData(TRUE);
              

              }

              void CformView::OnViewDlg()
              {
              CDlg dialog;
              // what is the value of the 'this' pointer here?
              dialog.dlg_level = form_sldr.GetPos();
              dialog.DoModal();
              }

              Since CDlg is a modal dialog, I question whether this will even work, since messages sent to its parent will be blocked until DoModal() returns.


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

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              B Offline
              B Offline
              bimgot
              wrote on last edited by
              #10

              void CDlg::OnTimer(UINT_PTR nIDEvent) { CDialog::OnTimer(nIDEvent); dlg_level = dlg_sldr.GetPos(); CformView* form = (CformView*) GetParent(); // form points to the main form class correctly form->form_level = dlg_level; form->UpdateData(TRUE); UpdateData(TRUE); } void CformView::OnViewDlg() { CDlg dialog; // this points to the main form class as this is a member function dialog.dlg_level = form_sldr.GetPos(); dialog.DoModal(); } i did consider a modal dialog as bieng inappropriate for this but was unsure as i dont actually need to control the main window whilst the dialog is open, i just want to update some variables..

              D 1 Reply Last reply
              0
              • B bimgot

                void CDlg::OnTimer(UINT_PTR nIDEvent) { CDialog::OnTimer(nIDEvent); dlg_level = dlg_sldr.GetPos(); CformView* form = (CformView*) GetParent(); // form points to the main form class correctly form->form_level = dlg_level; form->UpdateData(TRUE); UpdateData(TRUE); } void CformView::OnViewDlg() { CDlg dialog; // this points to the main form class as this is a member function dialog.dlg_level = form_sldr.GetPos(); dialog.DoModal(); } i did consider a modal dialog as bieng inappropriate for this but was unsure as i dont actually need to control the main window whilst the dialog is open, i just want to update some variables..

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

                bimgot wrote:

                ...i dont actually need to control the main window whilst the dialog is open, i just want to update some variables..

                So why call UpdateData() then?

                void CformView::OnViewDlg()
                {
                CDlg dialog;
                dialog.dlg_level = form_sldr.GetPos();
                dialog.DoModal();
                // is form_level correct at this point?
                }


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

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                B 1 Reply Last reply
                0
                • D David Crow

                  bimgot wrote:

                  ...i dont actually need to control the main window whilst the dialog is open, i just want to update some variables..

                  So why call UpdateData() then?

                  void CformView::OnViewDlg()
                  {
                  CDlg dialog;
                  dialog.dlg_level = form_sldr.GetPos();
                  dialog.DoModal();
                  // is form_level correct at this point?
                  }


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

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  B Offline
                  B Offline
                  bimgot
                  wrote on last edited by
                  #12

                  i dont believe it is no.. if i call void CformView::OnViewDlg() { CDlg dialog; dialog.dlg_level = form_sldr.GetPos(); dialog.DoModal(); form_sldr.SetPos(dialog.dlg_level); } this updates the variable when the dialog is closed, but i want to update the variable as the dialog is running.. trying the same but with: form_sldr.SetPos(form_level); after DoModal(); doesnt update the control in the same way..

                  D 1 Reply Last reply
                  0
                  • B bimgot

                    i dont believe it is no.. if i call void CformView::OnViewDlg() { CDlg dialog; dialog.dlg_level = form_sldr.GetPos(); dialog.DoModal(); form_sldr.SetPos(dialog.dlg_level); } this updates the variable when the dialog is closed, but i want to update the variable as the dialog is running.. trying the same but with: form_sldr.SetPos(form_level); after DoModal(); doesnt update the control in the same way..

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

                    bimgot wrote:

                    i want to update the variable as the dialog is running

                    Which contradicts your earlier statement of, "...i dont actually need to control the main window whilst the dialog is open." :confused:


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

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    B 1 Reply Last reply
                    0
                    • D David Crow

                      bimgot wrote:

                      i want to update the variable as the dialog is running

                      Which contradicts your earlier statement of, "...i dont actually need to control the main window whilst the dialog is open." :confused:


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

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      B Offline
                      B Offline
                      bimgot
                      wrote on last edited by
                      #14

                      sorry i was unclear here, i need to control the window in that i want to be able to update its variables, but i dont need to physically control or move the window..

                      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