combobox , foo(). , CStringArray CClass1, DDX combobox. DDX .
DDX, :
void AFXAPI
DDX_CBStringArray (CDataExchange* pDX, int nIDC, CStringArray& strings)
{
HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
bool bMine = false;
CComboBox* pCB = dynamic_cast<CComboBox*>(CWnd::FromHandlePermanent(hWndCtrl));
if (!pCB)
{
pCB = new CComboBox;
pCB->Attach(hWndCtrl);
bMine = true;
}
if (pDX->m_bSaveAndValidate)
{
strings.RemoveAll();
int nNumStrings = pCB->GetCount();
CString strVal("");
for (int x = 0; x < nNumStrings; ++x)
{
pCB->GetLBText(x, strVal);
strings.Add(strVal);
}
}
else
{
pCB->ResetContent();
INT_PTR nSize = strings.GetSize();
for (INT_PTR x = 0; x < nSize; ++x)
{
pCB->AddString(strings.GetAt(x));
}
}
if (bMine)
{
pCB->Detach();
delete pCB;
}
}
CStringArray CClass1 DDX. , ComboBox, StringArray , , DoModal(). .
CClass1 :
CClass1 : public CDialogEx
{
...
public:
CStringArray myStringEntries;
...
protected:
virtual void DoDataExchange(CDataExchange* pDX);
...
};
DoDataExchange :
void CClass1::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_CBStringArray(pDX, IDC_COMBO1, myStringEntries);
...
}
:
CClass1 dlg(this);
dlg.myStringEntries.Add("Some text");
dlg.myStringEntries.Add("More text");
dlg.DoModal();
, , CClass1:: foo() , CStringArray:
void CClass1::Foo()
{
myStringEntries.Add(TEXT("text"));
myStringEntries.Add(TEXT("more text"));
}