Adds a new item to a combo box control. The new item is added as the last item at level 0.
C
LONG WINAPI SftBox_AddString(HWND hwndCtl, LPCTSTR lpszText);
C++
LONG CSftBox::AddString(LPCTSTR lpszText);
hwndCtl
The window handle of the combo box control.
lpszText
A null-terminated string that is to be used as text for the cell of the first (or only) column.
The return value is the zero-based index of the newly added item. The return value is -1 if an error occurred.
The AddString function adds a new item to a combo box control. The new item is added as the last item at level 0.
By default, new items are added at level 0. Use SetItemLevel to change an item's level.
The combo box control creates a copy of the string supplied.
The WM_SETREDRAW Windows message (CWnd::SetRedraw) can be used to suppress the combo box control from being redrawn when many items are added. The use of WM_SETREDRAW is strongly recommended when adding many items to the combo box control, as it avoids significant processing while items are added and drastically reduces the time needed to populate the combo box control. WM_SETREDRAW (FALSE) should be used once, then all items should be added followed by one final WM_SETREDRAW (TRUE) message.
InsertString can be used to insert items at a specific position.
Items can be deleted using DeleteString.
If the dropdown portion of a dropdown or dropdown list combo box is visible, it is hidden when an item is added. This can be suppressed using SetRollupOnChange.
The maximum number of items is the maximum positive number which can be represented by the "int" type. However, virtual storage will be depleted well before this theoretical limit can be reached, not to mention the excessive load-time.
In a combo box control using a virtual data source, this function cannot be used and an error is returned.
CellInfo.Cell.colorBgSel = CellInfo.Cell.colorFgSel = SFTBOX_NOCOLOR;
CellInfo.Cell.colorBgEnd = CellInfo.Cell.colorBgSelEnd = SFTBOX_NOCOLOR;
CellInfo.Cell.colorProgress = CellInfo.Cell.colorProgressEnd = SFTBOX_NOCOLOR;
Sft_SetPictureColorSample(&CellInfo.Cell.CellPicture1, SAMPLE_SIZE, SAMPLE_SIZE, RGB(0, 0, 0), RGB(0, 0, 0));
SftBox_SetCellInfo(hwndBox, &CellInfo);
}
// The color of each item is saved as its item data.
index = SftBox_AddString(hwndBox, TEXT("Custom..."));
SftBox_SetText(hwndBox, index, 1, TEXT("Any color"));
SftBox_SetItemData(hwndBox, index, custom);
SetColorSample(hwndBox, index, custom);
for (i = 0 ; i < COLOR_COUNT ; ++i) {
index = SftBox_AddString(hwndBox, m_aColors[i].lpszName);
SftBox_SetText(hwndBox, index, 1, m_aColors[i].lpszDesc);
CellInfo.Cell.colorBgSel = CellInfo.Cell.colorFgSel = SFTBOX_NOCOLOR;
CellInfo.Cell.colorBgEnd = CellInfo.Cell.colorBgSelEnd = SFTBOX_NOCOLOR;
CellInfo.Cell.colorProgress = CellInfo.Cell.colorProgressEnd = SFTBOX_NOCOLOR;
Sft_SetPictureColorSample(&CellInfo.Cell.CellPicture1, SAMPLE_SIZE, SAMPLE_SIZE, RGB(0, 0, 0), RGB(0, 0, 0));
box.SetCellInfo(&CellInfo);
}
// The color of each item is saved as its item data.
index = box.AddString(_T("Custom..."));
box.SetText(index, 1, _T("Any color"));
box.SetItemData(index, custom);
SetColorSample(box, index, custom);
for (int i = 0 ; i < COLOR_COUNT ; ++i) {
index = box.AddString(m_aColors[i].lpszName);
box.SetText(index, 1, m_aColors[i].lpszDesc);See Also C/C++ API | Categories | Notifications