先发送LB_GETTEXTLEN消息得到文本长度,分配好字符串缓冲区
再发送LB_GETTEXT消息取得文本
LB_GETTEXTLEN
An application sends an LB_GETTEXTLEN message to retrieve the length of a string in a list box. LB_GETTEXTLEN 
wParam = (WPARAM) index;    // item index 
lParam = 0;                 // not used; must be zero 
 
Parameters
index 
Value of wParam. Specifies the zero-based index of the string. 
Windows 95 and Windows 98: The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than 32,767 items. Although the number of items is restricted, the total size in bytes of the items in a list box is limited only by available memory. Return Values
The return value is the length of the string, in characters, excluding the terminating null character. Under certain conditions, this value may actually be greater than the length of the text. For more information, see the following Res section.If the index parameter does not specify a valid index, the return value is LB_ERR. Res
Under certain conditions, the return value is larger than the actual length of the text. This occurs with certain mixtures of ANSI and Unicode, and is due to the operating system allowing for the possible existence of double-byte character set (DBCS) characters within the text. The return value, however, will always be at least as large as the actual length of the text; you can thus always use it to guide buffer allocation. This behavior can occur when an application uses both ANSI functions and common dialogs, which use Unicode. To obtain the exact length of the text, use the WM_GETTEXT, LB_GETTEXT, or CB_GETLBTEXT messages, or the GetWindowText function.QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.
LB_GETTEXT
An application sends an LB_GETTEXT message to retrieve a string from a list box. LB_GETTEXT 
wParam = (WPARAM) index;                // item index 
lParam = (LPARAM) (LPCTSTR) lpszBuffer; // address of buffer 
 
Parameters
index 
Value of wParam. Specifies the zero-based index of the string to retrieve. 
Windows 95 and Windows 98: The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than 32,767 items. Although the number of items is restricted, the total size in bytes of the items in a list box is limited only by available memory. lpszBuffer 
Value of lParam. Pointer to the buffer that will receive the string. The buffer must have sufficient space for the string and a terminating null character. An LB_GETTEXTLEN message can be sent before the LB_GETTEXT message to retrieve the length, in characters, of the string. 
Return Values
The return value is the length of the string, in characters, excluding the terminating null character. If index does not specify a valid index, the return value is LB_ERR. Res
If you create the list box with an owner-drawn style but without the LBS_HASSTRINGS style, the buffer pointed to by the lpszBuffer parameter will receive the 32-bit value associated with the item (the item data). QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.

解决方案 »

  1.   

    发送LB_GETCOUNT消息可以得到项目总数
    发送LB_GETCURSEL消息可以得到当前项目索引LB_GETCOUNT
    An application sends an LB_GETCOUNT message to retrieve the number of items in a list box. LB_GETCOUNT 
    wParam = 0; // not used; must be zero 
    lParam = 0; // not used; must be zero 
     
    Parameters
    This message has no parameters. Return Values
    The return value is the number of items in the list box, or LB_ERR if an error occurs. Res
    The returned count is one greater than the index value of the last item (the index is zero-based). QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Requires version 1.0 or later.
      Header: Declared in winuser.h.LB_GETCURSEL
    Send an LB_GETCURSEL message to retrieve the index of the currently selected item, if any, in a single-selection list box. LB_GETCURSEL 
    wParam = 0;     // not used; must be zero 
    lParam = 0;     // not used; must be zero 
     
    Parameters
    This message has no parameters. Return Values
    In a single-selection list box, the return value is the zero-based index of the currently selected item. If there is no selection, the return value is LB_ERR.Res
    Do not send this message to a multiple-selection list box.To retrieve the indexes of the selected items in a multiple-selection list box, use the LB_GETSELITEMS message. To determine whether the item that has the focus rectangle in a multiple selection list box is selected, use the LB_GETSEL message. If sent to a multiple-selection list box, LB_GETCURSEL returns the index of the item that has the focus rectangle. If no items are selected, it returns zero.QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Requires version 1.0 or later.
      Header: Declared in winuser.h.
      

  2.   

    楼上的哥们果然厉害,我想知道的不仅仅是MSDN里面的内容,比如
    LB_GETTEXTLEN
    LB_GETTEXT
    这两个常量的设置值在VB中是什么?
    承蒙写出范例,不胜感激
      

  3.   

    Const LB_GETTEXTLEN = &H18A
    Const LB_GETTEXT = &H189
      

  4.   

    这是太好了,我还想知道SendMessage的具体用法阿