CB_ADDSTRING

3.0

CB_ADDSTRING
wParam = 0;                         /* not used, must be zero   */
lParam = (LPARAM) (LPCSTR) lpsz;    /* address of string to add */

An application sends a CB_ADDSTRING message to add a string to the list box of a combo box. If the list box does not have the CBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list and the list is sorted.

Parameters

lpsz

Value of lParam. Points to the null-terminated string to be added. If the combo box was created with an owner-drawn style but without the CBS_HASSTRINGS style, the value of the lpsz parameter is stored rather than the string it would otherwise point to.

Return Value

The return value is the zero-based index to the string in the list box. The return value is CB_ERR if an error occurs; the return value is CB_ERRSPACE if insufficient space is available to store the new string.

Comments

If an owner-drawn combo box was created with the CBS_SORT style but not the CBS_HASSTRINGS style, the WM_COMPAREITEM message is sent one or more times to the owner of the combo box so that the new item can be properly placed in the list box.

To insert a string into a specific location within the list, use the CB_INSERTSTRING message.

Example

This example adds the string “my string” to a list box:

DWORD dwIndex;

dwIndex = SendDlgItemMessage(hdlg, ID_MYCOMBOBOX,
    CB_ADDSTRING, 0, (LPARAM) ((LPCSTR) "my string"));

See Also

CB_INSERTSTRING, WM_COMPAREITEM