Broad Network


Combo Box Messages

Windows Predefined Controls – Part 24

Volume - Windows User Interface

Forward: In this part of the series, we look at Combo Box Messages.

By: Chrysanthus Date Published: 29 Aug 2012

Introduction

This is part 24 of my series, Windows Predefined Controls. In order to understand this tutorial, you must have read all the previous tutorials of the series. In this part of the series, we look at Combo Box Messages.

Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.

Messages
The application can send a message to a control. The message can be sent with the SendMessage function. If you have forgotten the details of the SendMessage function, then read in this blog, the tutorial titled, Control Messages. If you have forgotten how to handle LOWORD and HIWORD, then read in this blog the tutorial titled, Edit Control Messages. Remember, a message can return a value. The returned value is actually returned by the SendMessage function. I now give you the messages and their meanings.

Message: Meaning
CB_ADDSTRING: This message adds 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. The wParam is not used (set it to NULL). The lParam is of type LPCTSTR (like LPARAM) and is a pointer to the null-terminated string to be added. 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.

CB_DELETESTRING: This message deletes a string in the list box of a combo box. The wParam is the zero-based index of the string to delete. The lParam parameter is not used (set it to NULL). The return value is a count of the strings remaining in the list. If the wParam parameter specifies an index greater than the number of items in the list, the return value is CB_ERR.

CB_DIR: This message adds names to the list displayed by the combo box. The message adds the names of directories and files that match a specified string and set of file attributes. CB_DIR can also add mapped drive letters to the list. The wParam has the attributes of the files or directories to be added to the combo box. This parameter can be one or more of the following values.
DDL_ARCHIVE: Includes archived files.
DDL_DIRECTORY: Includes subdirectories, which are enclosed in square brackets ([ ]).
DDL_DRIVES: All mapped drives are added to the list. Drives are listed in the form [-x-], where x is the drive letter.
DDL_EXCLUSIVE: Includes only files with the specified attributes. By default, read-write files are listed even if DDL_READWRITE is not specified.
DDL_HIDDEN: Includes hidden files.
DDL_READONLY: Includes read-only files.
DDL_READWRITE: Includes read-write files with no additional attributes. This is the default.
DDL_SYSTEM: Includes system files.
The lParam is an LPCTSTR pointer to a null-terminated string that specifies an absolute path, relative path, or file name. An absolute path can begin with a drive letter (for example, e:) or a UNC name (for example, \machinenamesharename). If the string specifies a file name or directory that has the attributes specified by the wParam parameter, the file name or directory is added to the list. If the file name or directory name contains wildcard characters (? or *), all files or directories that match the wildcard expression and have the attributes specified by the wParam parameter are added to the list displayed in the combo box. If the message succeeds, the return value is the zero-based index of the last name added to the list. If an error occurs, the return value is CB_ERR. If there is insufficient space to store the new strings, the return value is CB_ERRSPACE.

CB_FINDSTRING: This message searches the list box of a combo box for an item beginning with the characters in a specified string. The wParam is the zero-based index of the item preceding the first item to be searched. When the search reaches the bottom of the list box, it continues from the top of the list box back to the item specified by the wParam parameter. If wParam is –1, the entire list box is searched from the beginning. The lParam is a pointer to the null-terminated string that contains the characters for which to search. The search is not case sensitive, so this string can contain any combination of uppercase and lowercase letters. The return value is the zero-based index of the matching item. If the search is unsuccessful, it is CB_ERR.

CB_FINDSTRINGEXACT: This message finds the first list box string in a combo box that matches the string specified in the lParam parameter. This function is successful only if the specified string and a combo box item have the same length (except for the terminating null character) and the same characters. The wParam is the zero-based index of the item preceding the first item to be searched. When the search reaches the bottom of the list box, it continues from the top of the list box back to the item specified by the wParam parameter. If wParam is –1, the entire list box is searched from the beginning. The lParam is a pointer to the null-terminated string for which to search. This string can contain a complete file name, including the extension. The search is not case sensitive, so this string can contain any combination of uppercase and lowercase letters. The return value is the zero-based index of the matching item. If the search is unsuccessful, it is CB_ERR.

CB_GETCOMBOBOXINFO: This message gets information about the specified combo box. The wParam is not used (set it to NULL). The lParam is a pointer to a COMBOBOXINFO (see later) structure that receives the information. If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError (see later).

CB_GETCOUNT: This message gets the number of items in the list box of a combo box. The wParam is not used; it must be zero. The lParam is not used; it must be zero. The return value is the number of items in the list box. If an error occurs, it is CB_ERR.

CB_GETCUEBANNER: This message gets the cue banner text displayed in the edit control of a combo box. The wParam is a pointer to a Unicode (see later) string buffer that receives the cue banner text. The calling application is responsible for allocating the memory for the buffer. The buffer size must be equal to the length of the cue banner string in WCHARs (characters), plus 1—for the terminating NULL WCHAR. The lParam is the size of the buffer pointed to by lpcwText (see later) in WCHARs.  The message returns 1 if successful, or an error value otherwise. If there is no cue banner text to get, the return value is 0. If the calling application fails to allocate a buffer, or set lParam before sending this message, undefined behavior may result and the return value may not be reliable.

CB_GETCURSEL: This message is sent by the application to retrieve the index of the currently selected item, if any, in the list box of a combo box. The wParam is not used; it must be zero. The lParam is not used; it must be zero. The return value is the zero-based index of the currently selected item. If no item is selected, it is CB_ERR.

CB_GETDROPPEDCONTROLRECT: This message is sent to retrieve the screen coordinates of a combo box in its dropped-down state. The wParam is not used (set it to NULL). The lParam is a pointer to the RECT structure (has upper-left and lower-right coordinates) that receives the coordinates of the combo box in its dropped-down state. If the message succeeds, the return value is nonzero. If the message fails, the return value is zero.

CB_GETDROPPEDSTATE: This message determines whether the list box of a combo box is dropped down. The wParam is not used; it must be zero. The lParam is not used; it must be zero. If the list box is visible, the return value is TRUE; otherwise, it is FALSE.

CB_GETDROPPEDWIDTH: This message gets the minimum allowable width, in pixels, of the list box of a combo box with the CBS_DROPDOWN or CBS_DROPDOWNLIST style. The wParam is not used; it must be zero. The lParam is not used; it must be zero. If the message succeeds, the return value is the width, in pixels. If the message fails, the return value is CB_ERR.

CB_GETEDITSEL: This message gets the starting and ending character positions of the current selection in the edit control of a combo box. The wParam is a pointer to a DWORD value that receives the starting position of the selection. This parameter can be NULL. The lParam is a pointer to a DWORD value that receives the ending position of the selection. This parameter can be NULL. The return value is a zero-based DWORD value with the starting position of the selection in the LOWORD and with the ending position of the first character after the last selected character in the HIWORD.

CB_GETEXTENDEDUI: This message determines whether a combo box has the default user interface or the extended user interface. The wParam is not used; it must be zero. The lParam is not used; it must be zero. If the combo box has the extended user interface, the return value is TRUE; otherwise, it is FALSE.

CB_GETHORIZONTALEXTENT: This message gets the width, in pixels, that the list box can be scrolled horizontally (the scrollable width). This is applicable only if the list box has a horizontal scroll bar. The wParam is not used; it must be zero. The lParam is not used; it must be zero. The return value is the scrollable width, in pixels.

CB_GETITEMDATA: This message is sent to a combo box to retrieve the application-supplied value associated with the specified item in the combo box. The wParam is the zero-based index of the item. The lParam is not used (set it to NULL). The return value is the value associated with the item. If an error occurs, it is CB_ERR.

CB_GETITEMHEIGHT: This message determines the height of list items or the selection field in a combo box. The wParam is the combo box component whose height is to be retrieved. This parameter must be –1 to retrieve the height of the selection field. It must be zero to retrieve the height of list items. The lParam  is not used (set it to NULL). The return value is the height, in pixels, of the list items in a combo box.

CB_GETLBTEXTLEN: This message gets the length, in characters, of a string in the list of a combo box. The wParam is the zero-based index of the string. The lParam is not used (set it to NULL). The return value is the length of the string, in TCHARs (characters), excluding the terminating null character.

CB_GETLBTEXT: This message gets a string from the list of a combo box. The wParam is the zero-based index of the string to retrieve. The lParam is a  pointer to the buffer (char array) that receives the string. The buffer must have sufficient space for the string and a terminating null character. The return value is the length of the string, in TCHARs (characters), excluding the terminating null character. If wParam does not specify a valid index, the return value is CB_ERR.

CB_GETLOCALE: The locale is used to determine the correct sorting order of displayed text for combo boxes with the CBS_SORT style and text added by using the CB_ADDSTRING message. This message gets the current locale of the combo box. The wParam is not used; it must be zero. The lParam is not used; it must be zero. The return value specifies the current locale of the combo box. The HIWORD contains the country/region code and the LOWORD contains the language identifier.

CB_GETMINVISIBLE: This message gets the minimum number of visible items in the drop-down list of a combo box. The wParam is not used; it must be zero. The lParam is not used; it must be zero. The return value is the minimum number of visible items.

CB_GETTOPINDEX: This message is sent to retrieve the zero-based index of the first visible item in the list box portion of a combo box. Initially, the item with index 0 is at the top of the list box, but if the list box contents have been scrolled, another item may be at the top. The wParam is not used; it must be zero. The lParam is not used; it must be zero. If the message is successful, the return value is the index of the first visible item in the list box of the combo box. If the message fails, the return value is CB_ERR.

CB_INITSTORAGE: This message is sent before adding a large number of items to the list box portion of a combo box. This message allocates memory for storing list box items. The CB_INITSTORAGE message helps speed up the initialization of combo boxes that have a large number of items (over 100). It reserves the specified amount of memory so that subsequent CB_ADDSTRING, CB_INSERTSTRING (see below), and CB_DIR messages take the shortest possible time. The wParam is the number of items to add. The lParam is the amount of memory to allocate for item strings, in bytes. If the message is successful, the return value is the total number of items for which memory has been pre-allocated, that is, the total number of items added by all successful CB_INITSTORAGE messages. If the message fails, the return value is CB_ERRSPACE.

CB_INSERTSTRING: This message inserts a string or item data into the list of a combo box. Unlike the CB_ADDSTRING message, the CB_INSERTSTRING message does not cause a list with the CBS_SORT style to be sorted. The wParam is the zero-based index of the position at which to insert the string. If this parameter is –1, the string is added to the end of the list. The lParam is a pointer to the null-terminated string to be inserted. The return value is the index of the position at which the string was inserted. If an error occurs, the return value is CB_ERR. If there is insufficient space available to store the new string, it is CB_ERRSPACE.  Note: If the combo box has WS_HSCROLL style and you insert a string wider than the combo box, you should send a LB_SETHORIZONTALEXTENT message to ensure the horizontal scrollbar appears.

CB_LIMITTEXT: This message limits the length of the text the user may type into the edit control of a combo box. The CB_LIMITTEXT message limits only the text the user can enter. It has no effect on any text already in the edit control when the message is sent, nor does it affect the length of the text copied to the edit control when a string in the list box is selected. The default limit to the text a user can enter in the edit control is 30,000 TCHARs (characters). The wParam is the maximum number of TCHARs the user can enter, not including the terminating null character. If this parameter is zero, the text length is limited to 0x7FFFFFFE characters. The lParam is not used (set it to NULL). The return value is always TRUE. If the combo box does not have the CBS_AUTOHSCROLL style, setting the text limit to be larger than the size of the edit control has no effect.

CB_RESETCONTENT: This message removes all items from the list box and edit control of a combo box. The wParam is not used; it must be zero. The lParam is not used; it must be zero. This message always returns CB_OKAY.

CB_SELECTSTRING: This message searches the list of a combo box for an item that begins with the characters in a specified string. If a matching item is found, it is selected and copied to the edit control. The wParam is the zero-based index of the item preceding the first item to be searched. When the search reaches the bottom of the list, it continues from the top of the list back to the item specified by the wParam parameter. If wParam is –1, the entire list is searched from the beginning. The lParam is a pointer to the null-terminated string that contains the characters for which to search. The search is not case sensitive, so this string can contain any combination of uppercase and lowercase letters. If the string is found, the return value is the index of the selected item. If the search is unsuccessful, the return value is CB_ERR and the current selection is not changed.

CB_SETCUEBANNER: This message sets the cue banner text that is displayed for the edit control of a combo box. The wParam must be zero. The lParam is a pointer to a null-terminated Unicode (see later) string buffer that contains the text. Returns 1 if successful, or an error value otherwise.

CB_SETCURSEL: This message is sent to select a string in the list of a combo box. If necessary, the list scrolls the string into view. The text in the edit control of the combo box changes to reflect the new selection, and any previous selection in the list is removed. The wParam specifies the zero-based index of the string to select. If this parameter is –1, any current selection in the list is removed and the edit control is cleared.
The lParam is not used (set it to NULL). If the message is successful, the return value is the index of the item selected. If wParam is greater than the number of items in the list or if wParam is –1, the return value is CB_ERR and the selection is cleared.

CB_SETDROPPEDWIDTH: This message is sent to set the maximum allowable width, in pixels, of the list box of a combo box with the CBS_DROPDOWN or CBS_DROPDOWNLIST style. The wParam is the minimum allowable width of the list box, in pixels. The lParam is not used (set it to NULL). If the message is successful, The return value is the new width of the list box. If the message fails, the return value is CB_ERR.

CB_SETEDITSEL: This message is sent to select characters in the edit control of a combo box. The wParam is not used (set it to NULL). The LOWORD of lParam specifies the starting position. If the LOWORD is –1, the selection, if any, is removed. The HIWORD of lParam specifies the ending position. If the HIWORD is –1, all text from the starting position to the last character in the edit control is selected. If the message succeeds, the return value is TRUE. If the message is sent to a combo box with the CBS_DROPDOWNLIST style, it is CB_ERR.

CB_SETEXTENDEDUI: This message is sent to select either the default UI or the extended UI for a combo box that has the CBS_DROPDOWN or CBS_DROPDOWNLIST style. The wParam is a BOOL that specifies whether the combo box uses the extended UI (TRUE) or the default UI (FALSE). The lParam is not used (set it to NULL). If the operation succeeds, the return value is CB_OKAY. If an error occurs, it is CB_ERR.

CB_SETHORIZONTALEXTENT: This message is sent to set the width, in pixels, by which a list box can be scrolled horizontally (the scrollable width). If the width of the list box is smaller than this value, the horizontal scroll bar horizontally scrolls items in the list box. If the width of the list box is equal to or greater than this value, the horizontal scroll bar is hidden or, if the combo box has the CBS_DISABLENOSCROLL style, disabled. The wParam specifies the scrollable width of the list box, in pixels. The lParam is not used (set it to NULL).

CB_SETITEMDATA: This message is sent to set the value associated with the specified item in a combo box. The wParam specifies the item's zero-based index. The lParam specifies the new value to be associated with the item. If an error occurs, the return value is CB_ERR.

CB_SETITEMHEIGHT: This message is sent to set the height of list items or the selection field in a combo box. The wParam specifies the component of the combo box for which to set the height. This parameter must be –1 to set the height of the selection field. It must be zero to set the height of list items The lParam specifies the height, in pixels, of the combo box component identified by wParam. If the index or height is invalid, the return value is CB_ERR.

CB_SETLOCALE: This message is sent to set the current locale of the combo box. If the combo box has the CBS_SORT style and strings are added using CB_ADDSTRING, the locale of a combo box affects how list items are sorted. The wParam specifies the locale identifier for the combo box to use for sorting when adding text. The lParam is not used (set it to NULL). The return value is the previous locale identifier. If wParam specifies a locale not installed on the system, the return value is CB_ERR and the current combo box locale is not changed. Note: You can use the MAKELCID macro (see later) to construct a locale identifier and the MAKELANGID macro (see later) to construct a language identifier. The language identifier is made up of a primary language identifier and a sub language identifier.

CB_SETMINVISIBLE: This message is sent to set the minimum number of visible items in the drop-down list of a combo box. The wParam specifies the minimum number of visible items. The lParam is not used; it must be zero. If the message is successful, the return value is TRUE. Otherwise the return value is FALSE.

CB_SETTOPINDEX: This message is sent to ensure that a particular item is visible in the list box of a combo box. The system scrolls the list box contents so that either the specified item appears at the top of the list box or the maximum scroll range has been reached. The wParam specifies the zero-based index of the list item. The lParam is not used (set it to NULL). If the message is successful, the return value is zero. If the message fails, the return value is CB_ERR.

CB_SHOWDROPDOWN: This message is sent to show or hide the list box of a combo box that has the CBS_DROPDOWN or CBS_DROPDOWNLIST style. The wParam is a BOOL that specifies whether the drop-down list box is to be shown or hidden. A value of TRUE shows the list box; a value of FALSE hides it. The lParam is not used (set it to NULL). The return value is always TRUE.

That is it for this part of the series. We stop here and continue in the next part.

Chrys
NEXT

Comments

Become the Writer's Fan
Send the Writer a Message