Code

 

CB_ADDSTRING Message


An application sends a CB_ADDSTRING message to add a string to the list box of a combo box. If the combo 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.

Syntax

To send this message, call the SendMessage function as follows.

lResult = SendMessage(     // returns LRESULT in lResult    (HWND) hWndControl,     // handle to destination control    (UINT) CB_ADDSTRING,     // message ID    (WPARAM) wParam,     // = 0; not used, must be zero   (LPARAM) lParam     // = (LPARAM) (LPCTSTR) lParam;);

Parameters

wParam
This parameter is not used.
lParam
Pointer to the null-terminated string to be added. If you create the combo box with an owner-drawn style but without the CBS_HASSTRINGS style, the value of the lParam parameter is stored as item data rather than the string it would otherwise point to. The item data can be retrieved or modified by sending the CB_GETITEMDATA or CB_SETITEMDATA message.

Return Value

The return value is the zero-based index to the string in the list box of the combo box. If an error occurs, the return value is CB_ERR. If insufficient space is available to store the new string, it is CB_ERRSPACE.

Remarks

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

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

If the combo box has WS_HSCROLL style and you add a string wider than the combo box, send a LB_SETHORIZONTALEXTENT message to ensure the horizontal scrollbar appears.

Comclt32.dll version 5.0 or later: If CBS_LOWERCASE or CBS_UPPERCASE is set, the Unicode version of CB_ADDSTRING alters the string. If using read-only global memory, this causes the application to fail.

 posted on 2009-10-29 17:22  wParma  阅读(617)  评论(0编辑  收藏  举报