CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Location
    Surrey, England
    Posts
    23

    Using Dialog Data Exchange

    Hello,

    I am a beginner VC++ 6.0 professional programmer using Win98.

    I have the following problem:

    I am trying to use dialog data exchange (DDX) with a dialog box in my
    application, in order to retrieve data from a database table, edit it,
    and then save it. I am however having problems.

    I have created a dialogbox resource, and associated it with a CDialog
    class in ClassWizard. In the Foreigh Class box I have selected a
    CDAORecordset class I had created previously. In the Foreign Variable
    box I put the name "m_pSet". I then created member variables for all my
    edit boxes in the dialog, selecting fields from the dropdown in the
    Member Variable section of ClassWizard.

    After this, the ClassWizard generated the following method in my CDialog
    class:

    void CRView3:oDataExchange(CDataExchange* pDX)
    {
    CDialog:oDataExchange(pDX);
    //{{AFX_DATA_MAP(CRView3)
    DDX_Control(pDX, IDOK, m_OK);
    DDX_Control(pDX, IDCANCEL, m_Cancel);
    DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_DisplayName, m_pSet);
    DDX_FieldText(pDX, IDC_EDIT2, m_pSet->m_Email, m_pSet);
    //}}AFX_DATA_MAP
    }



    It also initialised m_pSet to NULL in the CDialog constructor. But it
    did no more than that.

    My first problem is that ClassWizard created no code actually to open my
    recordset class. So I did that as follows:

    void CRView3::GetRecordset()
    {
    m_pSet = new CAddrRset1(NULL);
    m_pSet->Open();
    }



    After the above measures the dialog box worked OK in that it presented
    me with the right data. However, it won't save any changes I make back
    to the database. This is my second problem. I thought that all this
    was taken care of by dialog data exchange.

    I would be very grateful for code showing how to set up dialog data
    exchange so that it works properly and saves changes back to the
    database.

    Thanks,
    TrimTrom

    ----------------------------------
    Email: [email protected]
    Surrey, England
    ----------------------------------


  2. #2
    Join Date
    Jul 1999
    Location
    Pasadena, CA - USA
    Posts
    351

    Re: Using Dialog Data Exchange

    Hi,

    The DDX functions only update the member variables. For example, taking the data from an edit box and putting it into a member variable of CString. What you do with the vars is left up to you. Typically the caller initializes the variables before calling the dialog and reads them after the dialog is closed successfully. I know this doesn't answer your question directly, but hopefully it helps.



    Regards,

    Paul Belikian

  3. #3
    Join Date
    Jul 1999
    Location
    Uitca, NY
    Posts
    120

    Re: Using Dialog Data Exchange

    Here is a sample of a dialog box call, titled Parameters. The call is in the View class and created from the ID_PARAMETERS Command function generated by the ClassWizard. This is a multithreading program, so there are hMutexs. It shows data initialization before calling the dialog box and retrieving the new data when the box is exited with the OK button:

    // Parameters dialog box routine.
    void CMandelbrotView::OnParameters()
    {
    CParameters dlg;

    // Initialize dialog data
    ::WaitForSingleObject( HMutexActive, INFINITE );
    dlg.m_dCiMax = parametersActive.m_dCiMax;
    dlg.m_dCiMin = parametersActive.m_dCiMin;
    dlg.m_dCrMax = parametersActive.m_dCrMax;
    dlg.m_dCrMin = parametersActive.m_dCrMin;
    dlg.m_dLMaximum = parametersActive.m_dLMax;
    dlg.m_nNMax = parametersActive.m_nNMax;
    dlg.m_nPalSize = parametersActive.m_nPalSize;
    dlg.m_nColorShift = parametersActive.m_nColorShift;
    ::ReleaseMutex( HMutexActive );

    // Invoke the dialog box
    if ( dlg.DoModal() == IDOK )
    {
    // If dialog box is left with OK button make sure
    // Maximum and minimum values are properly set.
    // Exit with no change if Max = Min in a set.

    if ( ( dlg.m_dCiMax != dlg.m_dCiMin ) && ( dlg.m_dCrMax != dlg.m_dCrMin ) )
    {
    ::WaitForSingleObject( HMutexActive, INFINITE );
    parametersActive.m_dCiMax = max( dlg.m_dCiMax, dlg.m_dCiMin );
    parametersActive.m_dCiMin = min( dlg.m_dCiMax, dlg.m_dCiMin );
    parametersActive.m_dCrMax = max( dlg.m_dCrMax, dlg.m_dCrMin );
    parametersActive.m_dCrMin = min( dlg.m_dCrMax, dlg.m_dCrMin );
    parametersActive.m_dLMax = dlg.m_dLMaximum;
    parametersActive.m_nNMax = dlg.m_nNMax;
    parametersActive.m_nPalSize = dlg.m_nPalSize;
    parametersActive.m_nColorShift = dlg.m_nColorShift;
    ::ReleaseMutex( HMutexActive );
    }

    OnNewParameters(); // Update undo parameter array

    // Then redraw the window
    Invalidate();
    }
    }






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured