CComboBox::InitStorage
存储分配的内存组合框的列表框部分的列表框项。
int InitStorage(
int nItems,
UINT nBytes
);
参数
nItems
指定项的数目添加。nBytes
在字节指定大量内存,为项目字符串赋值。
返回值
如果成功,组合框的列表框部分可以存储项的最大数目,在内存重新分配需要之前,否则 CB_ERRSPACE,这意味着没有足够的内存可用。
备注
在添加大量项之前调用此功能。CComboBox的列表框部分。
Windows 95 /98仅: wParam 参数被限制为16位值。 这意味着列表框不能超过32,767个项目。 虽然项的数量的限制,项目的总大小在列表框中仅受可用内存的限制。
此功能有助于加速初始化具有大量项的列表框(超过100)。 它指定预分配的内存量,以便后续 AddString、 InsertString和 Dir 函数花费最短的时间。 您可以使用参数的估计。 如果估计锁争,一些额外的内存分配您;如果低估数据,正常分配给多个预分配的数量的项目。
示例
// Initialize the storage of the combo box to be 256 strings with
// about 10 characters per string, performance improvement.
int nAlloc = pmyComboBox->InitStorage(256, 10);
ASSERT(nAlloc != CB_ERRSPACE);
// Add 256 items to the combo box.
CString strAdd;
for (int i = 0; i < 256; i++)
{
strAdd.Format(_T("item string %d"), i);
m_pComboBox->AddString(strAdd);
}
要求
Header: afxwin.h