Share via


CComboBox::InitStorage

Allocates memory for storing list box items in the list-box portion of the combo box.

int InitStorage(
   int nItems,
   UINT nBytes 
);

Parameters

  • nItems
    Specifies the number of items to add.

  • nBytes
    Specifies the amount of memory, in bytes, to allocate for item strings.

Return Value

If successful, the maximum number of items that the list-box portion of the combo box can store before a memory reallocation is needed, otherwise CB_ERRSPACE, meaning not enough memory is available.

Remarks

Call this function before adding a large number of items to the list-box portion of the CComboBox.

Windows 95/98 only: The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than 32,767 items. Although the number of items is restricted, the total size of the items in a list box is limited only by available memory.

This function helps speed up the initialization of list boxes that have a large number of items (more than 100). It preallocates the specified amount of memory so that subsequent AddString, InsertString, and Dir functions take the shortest possible time. You can use estimates for the parameters. If you overestimate, some extra memory is allocated; if you underestimate, the normal allocation is used for items that exceed the preallocated amount.

Example

// 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);
}

Requirements

Header: afxwin.h

See Also

Reference

CComboBox Class

Hierarchy Chart

CComboBox::CComboBox

CComboBox::Create

CComboBox::ResetContent

CB_INITSTORAGE

Other Resources

CComboBox Members