Let's take ListBox and Edit as examples.
2025-11-10
Written by: xiaobin
After dragging a “listbox” from the “Toolbox,” right-click and select “Add Variable…”


m_Types.AddString(_T("MS-Access"));
m_Types.AddString(_T("MSSQL"));
m_Types.AddString(_T("MySQL"));
for example:
int iCurSel = 0;
iCurSel = m_Types.GetCurSel();
CString tmp;
tmp.Format(_T("%d"), iCurSel);
AfxMessageBox(tmp);
void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, m_Server);
}
change:
void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_Server);
}
Otherwise, the following will occur:
error C2664: 'void DDX_Control(CDataExchange *,int,CWnd &)' : cannot convert argument 3 from 'CString' to 'CWnd &'
m_Types.GetText(iCurSel, tmp);
m_Server = tmp;
// Update the display
UpdateData(FALSE);