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

UI Data exchange

Win32 subsystem provides a wide range of UI controls and MFC framework has DDX or dialog data exchange macro for each type of UI controls. Here we are discussing the data exchange macros and suitable member variables in dialog class for most common UI controls available in Win32.

EditBox

Editbox mostly contains a simple text and CString is mostsuitable Data ehchanged in an editbox. However data can be in the form of integer, floating point numbers. Morefover formatted data can be exchanged in form of currency, date and time, GUID, file time etc.

void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, BYTE& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, short& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, int& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, UINT& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, long& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, DWORD& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, LONGLONG& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, ULONGLONG& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, CString& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, LPTSTR value,int nMaxLen);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, float& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, double& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, COleCurrency& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, COleDateTime& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, GUID& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, DECIMAL& value);
void AFXAPI DDX_Text(CDataExchange* pDX, int nIDC, FILETIME& value);

Checkbox

Checkbox can have two states - checked or unchecked. Thus a BOOL/boolean/integer is suitable variable for exhange.

void AFXAPI DDX_Check(CDataExchange* pDX, int nIDC, int& value);

Radio button

Radio button is like Checkbox can have two states - checked or unchecked. Thus a BOOL/boolean/integer is suitable variable for exhange.

void AFXAPI DDX_Radio(CDataExchange* pDX, int nIDC, int& value);

Combo box

Combo box is a single selection and thus integer can be used to check the position of the selection or a string can be used to get the selected index text.

void AFXAPI DDX_CBString(CDataExchange* pDX, int nIDC, CString& value);
void AFXAPI DDX_CBIndex(CDataExchange* pDX, int nIDC, int& index);
void AFXAPI DDX_CBStringExact(CDataExchange* pDX, int nIDC, CString& value);

List box - single selection

A single selection is same like a Combo box. An integer can be used to check the position of the selection or a string can be used to get the selected index text.
void AFXAPI DDX_LBString(CDataExchange* pDX, int nIDC, CString& value);
void AFXAPI DDX_LBIndex(CDataExchange* pDX, int nIDC, int& index);
void AFXAPI DDX_LBStringExact(CDataExchange* pDX, int nIDC, CString& value);

List box - multi selection

List box often used for getting multiple selections. Data exchange is little bit complex when multiple selection is Involved. An array of CString or Integer is used. There is no MFC define DDX macro and user can write a function as below.

void AFXAPI DDX_LBStringArray(CDataExchange* pDX, int nIDC, CStringArray& value)
{
    HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
    if (pDX->m_bSaveAndValidate)
    {
      char szSelection[64];
      CArray <int , int> aListBoxSel;
      int nNbItems = ListBox_GetSelCount(hWndCtrl);
      aListBoxSel.SetSize(nNbItems);
10        ListBox_GetSelItems(hWndCtrl, nNbItems, aListBoxSel.GetData());
11        value.RemoveAll();
12 
13        for (int i=0; i < nNbItems;i++)
14        {
15          ListBox_GetText(hWndCtrl, aListBoxSel.GetAt(i), szSelection);
16          value.Add(szSelection);
17        }
18      }
19      else
20      {
21      for (int i = 0; i < value.GetSize();i++)
22      ListBox_AddString(hWndCtrl,value.GetAt(i));
23      }
24  }

Scrollbar

Scrollbar holds a position and thus integer can be used.

void AFXAPI DDX_Scroll(CDataExchange* pDX, int nIDC, int& value);

Slider

Slider is very similer to Scrollbar which holds a position and thus integer can be used.

void AFXAPI DDX_Slider(CDataExchange* pDX, int nIDC, int& value);

IP Address control

IP address (IPv4) is a unsigned 32bit integer splitted in four parts by BYTE in for small boxes in IP address controller. A 32bit unsigned integer or DWORD is used for data exchange.

void AFXAPI DDX_IPAddress(CDataExchange* pDX, int nIDC, DWORD& value);

Month Calender

Month Calender contains a date time and MFC has CTime, COleDateTime, FILETIME etc as data type.

void AFXAPI DDX_MonthCalCtrl(CDataExchange* pDX, int nIDC, CTime& value);
void AFXAPI DDX_MonthCalCtrl(CDataExchange* pDX, int nIDC, COleDateTime& value);
void AFXAPI DDX_MonthCalCtrl(CDataExchange* pDX, int nIDC, FILETIME& value);

Date Time control

Date Time control like Month Calender contains a date time and MFC has CString, CTime, COleDateTime, FILETIME etc as data type.

void AFXAPI DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, CString& value);
void AFXAPI DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, CTime& value);
void AFXAPI DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, COleDateTime& value);
void AFXAPI DDX_DateTimeCtrl(CDataExchange* pDX, int nIDC, FILETIME& value);

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 Wed 30 Apr/2014 05:40:04(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.