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 CView from CDialog MFC???

Accessing CView from CDialog MFC???

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestionlearning
7 Posts 4 Posters 1 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.
  • B Offline
    B Offline
    bimgot
    wrote on last edited by
    #1

    hi there, i'm building a SDI form application and thought it might be good to have a dialog box as a set of alternate controls for a few parameters of that application.. is this possible? i've created the dialog box resource but i'm having some trouble getting them to talk to one another.. for example - the main form contains a few slider controls for parameters and this all works fine, but i also want to be able to control these parameters from a seperate dialog box, and ideally i'd want them to correspond on submission (if moved in the dialog box, the original is updated..) is there any way to link 2 controls to 1 parameter? should i be working with a MDI? thanks in advance!

    B 1 Reply Last reply
    0
    • B bimgot

      hi there, i'm building a SDI form application and thought it might be good to have a dialog box as a set of alternate controls for a few parameters of that application.. is this possible? i've created the dialog box resource but i'm having some trouble getting them to talk to one another.. for example - the main form contains a few slider controls for parameters and this all works fine, but i also want to be able to control these parameters from a seperate dialog box, and ideally i'd want them to correspond on submission (if moved in the dialog box, the original is updated..) is there any way to link 2 controls to 1 parameter? should i be working with a MDI? thanks in advance!

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      As with any dialog, some member variables linked to the dialogs slider controls in the DoDataExchange should be sufficient. After the CDialog derived class is instantiated, have the view set the dialogs members. Once DoModal returns with IDOK, but before the CDialog derived class goes out of scope, your view code can get the last position of the slider and update its controls accordingly. /* Obviously, there will be more to it than this but the basic idea is the same */ void CTestsliderView::OnShowDialog() { // TODO: Add your command handler code here CSliderDialog dlg; dlg.m_nSlider=15; if (dlg.DoModal()==IDOK) { TRACE("New Slider pos = %d\n",dlg.m_nSlider); } }

      K B 2 Replies Last reply
      0
      • B bob16972

        As with any dialog, some member variables linked to the dialogs slider controls in the DoDataExchange should be sufficient. After the CDialog derived class is instantiated, have the view set the dialogs members. Once DoModal returns with IDOK, but before the CDialog derived class goes out of scope, your view code can get the last position of the slider and update its controls accordingly. /* Obviously, there will be more to it than this but the basic idea is the same */ void CTestsliderView::OnShowDialog() { // TODO: Add your command handler code here CSliderDialog dlg; dlg.m_nSlider=15; if (dlg.DoModal()==IDOK) { TRACE("New Slider pos = %d\n",dlg.m_nSlider); } }

        K Offline
        K Offline
        ksrameshkanth
        wrote on last edited by
        #3

        bob16972's idea is good, at the same time u can have "CSliderDialog dlg;" is the member of CTestsliderView class.so that across the view u can access ur dialog very easily.

        1 Reply Last reply
        0
        • B bob16972

          As with any dialog, some member variables linked to the dialogs slider controls in the DoDataExchange should be sufficient. After the CDialog derived class is instantiated, have the view set the dialogs members. Once DoModal returns with IDOK, but before the CDialog derived class goes out of scope, your view code can get the last position of the slider and update its controls accordingly. /* Obviously, there will be more to it than this but the basic idea is the same */ void CTestsliderView::OnShowDialog() { // TODO: Add your command handler code here CSliderDialog dlg; dlg.m_nSlider=15; if (dlg.DoModal()==IDOK) { TRACE("New Slider pos = %d\n",dlg.m_nSlider); } }

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

          thanks alot this looks like it will work for me, however i've just had a quick look and when i try to set the position of the dialog slider from the view code (ie "dlg.m_nSlider.SetPos(0)) i get an assertion failure with "afxcmn.inl" which breaks at the SetPos function.. have i missed something? in the dialog code i've set up a member variable linked to the dialog slider with DoDataExchange and i've also used OnInitDialog() to set the range of the slider.. but other than that i think its as above.. thanks in advance

          J B 2 Replies Last reply
          0
          • B bimgot

            thanks alot this looks like it will work for me, however i've just had a quick look and when i try to set the position of the dialog slider from the view code (ie "dlg.m_nSlider.SetPos(0)) i get an assertion failure with "afxcmn.inl" which breaks at the SetPos function.. have i missed something? in the dialog code i've set up a member variable linked to the dialog slider with DoDataExchange and i've also used OnInitDialog() to set the range of the slider.. but other than that i think its as above.. thanks in advance

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

            You don't show code but I bet you're calling SetPos before the dialog is created. You need to do something like what you were shown originally by bob16972 CSliderDlg dlg (this); dlg.m_nSlider = <value>; // can't use with SetPos becaues doesn't exist yet if (dlg.DoModal () == IDOK) { //set view's slider to dlg.m_nSlider } The actual call to SetPos should be from within the CSliderDlg's OnInitDialog. Also, you need to do something in your CSliderDlg::OnOK to put the position of the slider into the m_nSlider variable. I haven't played with sliders and DDX to know offhand if the DDX does this for you on slider controls. Judy

            1 Reply Last reply
            0
            • B bimgot

              thanks alot this looks like it will work for me, however i've just had a quick look and when i try to set the position of the dialog slider from the view code (ie "dlg.m_nSlider.SetPos(0)) i get an assertion failure with "afxcmn.inl" which breaks at the SetPos function.. have i missed something? in the dialog code i've set up a member variable linked to the dialog slider with DoDataExchange and i've also used OnInitDialog() to set the range of the slider.. but other than that i think its as above.. thanks in advance

              B Offline
              B Offline
              bob16972
              wrote on last edited by
              #6

              You'll assert because the windows don't exist unless the dialog is modal (I'm not considering modeless since that comes with it's own set of issues). The dialog object does exist and that's where the members come into play. Make sure the member variables you create are for the value and not the slider control. Notice that the member in the sample is of type int and not CSliderCtrl (You could create one of both so you can get to the control from within the dialog class, just remember not to use it if the dialog window does not exist.) Separate the dialog object from the window and the asserts will make more sense. Hope that helps

              B 1 Reply Last reply
              0
              • B bob16972

                You'll assert because the windows don't exist unless the dialog is modal (I'm not considering modeless since that comes with it's own set of issues). The dialog object does exist and that's where the members come into play. Make sure the member variables you create are for the value and not the slider control. Notice that the member in the sample is of type int and not CSliderCtrl (You could create one of both so you can get to the control from within the dialog class, just remember not to use it if the dialog window does not exist.) Separate the dialog object from the window and the asserts will make more sense. Hope that helps

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

                thanks very much, fairly new to MFC so sorry if that was a bit obvious!

                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