Accessing CView from CDialog MFC???
-
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!
-
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!
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); } }
-
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); } }
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.
-
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); } }
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
-
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
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 -
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
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
-
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