EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of VC++/WIN32/MFC Questions #Next question

CDataExchange

CDataExchange class is used to pass the argument in exchange routine where data is exchanged between UI control and class member variables. We are going to discuss MFC data exchange mechanism in our next few sections and before that it is necessary to understand CDataExchange and its members. CDataExchange object primarily holds the context of dialog or window pointer, direction of data exchange and necessary functions needed for data exchange. Lets see the class members and functions of CDataExchange.

CDataExchange class

class CDataExchange
{
public :
  BOOL m_bSaveAndValidate;
  CWnd* m_pDlgWnd;
  HWND PrepareCtrl(int nIDC);     
  HWND PrepareEditCtrl(int nIDC); 
10    void Fail();
11 
12    CDataExchange(CWnd* pDlgWnd, BOOL bSaveAndValidate);
13 
14    COleControlSite* PrepareOleCtrl(int nIDC);
15 
16 
17      UINT m_idLastControl;
18    BOOL m_bEditLastControl;
19  };

CDataExchange elements

  • CDataExchange - This is the constructor of the CDataExchange and it takes the Dialog/top window pointer and direction of data exchange.
  • m_bSaveAndValidate - Member variable to hold direction of the data exchange.
  • m_pDlgWnd - Member variable to hold Dialog/top window pointer
  • PrepareCtrl/PrepareEditCtrl - Member function to retrieve window handle of the control from the ID given in argument.
  • PrepareOleCtrl - Member function to retrieve COleControlSite handle of the control from the ID given in argument.
  • m_idLastControl - Member variable to hold last control used (for validation)
  • m_bEditLastControl - Member variable to hold if last control was an edit item
  • Fail - expection handling function

CDataExchange and data exchange

Sample code on how CDataExchange object is used in UpdateData() call and passed to DoDataExchange()

BOOL CWnd::UpdateData(BOOL bSaveAndValidate)
{
   CDataExchange DX(this, bSaveAndValidate);
   DoDataExchange(&DX);
}
/* UpdateData with TRUE is called */
BOOL CDialog::OnInitDialog()
{
  /* called by MFC framework */
10    /* Default values go to UI */
11    UpdateData(FALSE);
12  }
13 
14  /* UpdateData with FALSE is called */
15  void CUserDialog::OnSubmit()
16  {
17    /* called by user */
18    /* UI values go to members */
19    UpdateData(TRUE);
20  }

You have viewed 1 page out of 109. Your VC++ learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

#Programming Windows, Fifth Edition (Developer Reference)
#Programming Applications for Microsoft Windows (Microsoft Programming Series)
#Programming Windows with MFC, Second Edition
#Visual C++ Programming
#Programming Microsoft Visual C++, Fifth Edition

* #1 webmaster Sun 27 Apr/2014 14:48:14(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.