Windows API Guide: Reference: Messages


Platforms

  • Windows 95: Supported.
  • Windows 98: Supported.
  • Windows NT: Requires Windows NT 3.1 or later.
  • Windows 2000: Supported.
  • Windows CE: Requires Windows CE 1.0 or later.

Description & Usage

Sending the CB_GETCOUNT message determines how many items exist in the list box portion of a combo box control. Keep in mind that the list box items are zero-based; the first item has an index of zero, and the last one has an index of the count minus one.

Return Value

If successful, the message returns the number of items that are in the list box portion of a combo box control. If an error occured, the message returns -1.

Visual Basic-Specific Issues

None.

Parameters

wParam
Not used -- set to 0.
lParam
Not used -- set to 0.

Constant Definitions

Const CB_GETCOUNT = &H146

Example

' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd _ As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long Public Const CB_GETCOUNT = &H146 Public Const CB_GETLBTEXT = &H148 Public Const CB_GETLBTEXTLEN = &H149 ' Display the text of the second-to-last item in the list box portion ' of combo box Combo1. Dim count As Long       ' number of items in the combo box Dim s2l As Long         ' index of the second-to-last item Dim itemtext As String  ' text of that item Dim textlen As Long     ' length of the item text ' Figure out the index of the second-to-last item by subtracting two from ' the total item count (remember, the index is zero-based). count = SendMessage(Combo1.hWnd, CB_GETCOUNT, ByVal CLng(0), ByVal CLng(0)) s2l = count - 2 ' Make the string long enough to receive that item's text. textlen = SendMessage(Combo1.hWnd, CB_GETLBTEXTLEN, ByVal s2l, ByVal CLng(0)) itemtext = Space(textlen) & vbNullChar ' Get the item text and remove the trailing null. textlen = SendMessage(Combo1.hWnd, CB_GETLBTEXT, ByVal s2l, ByVal itemtext) itemtext = Left(itemtext, textlen) Finally, display the result. Debug.Print "The second-to-last item is "; itemtext

Category

Combo Boxes

Back to the Message list.
Back to the Reference section.


Last Modified: April 16, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/c/cb_getcount.html



Windows API Guide
Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
ISBN: B001V0KQIY
EAN: N/A
Year: 1998
Pages: 610

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net