'listbox text
'   从列表框检索一个字符串。
'   hWndControl: 控件的句柄 (例如  HWND_FORM1_LISTBOX1)                  
'   nIndex:      从零开始的索引。
'   Returns:     If an error occurs, %LB_ERR is returned, otherwise
'                the length of the string is returned.
Function FF_ListBox_GetText(ByVal hWndControl as HWnd, ByVal nIndex as Long) as CWSTR
   
   Dim nBufferSize as Long
   Dim nBuffer() as UByte 
   '检查窗口句柄是否有效
   If IsWindow(hWndControl) Then
      
      '得到的文本的长度
      nBufferSize = SendMessageW(hWndControl, LB_GETTEXTLEN, nIndex, 0)
      If (nBufferSize = 0) Or (nBufferSize = LB_ERR) Then   return ""
      'Add an extra character for the Nul terminator
     redim nBuffer (nBufferSize*2 + 2)
      
      If SendMessageW(hWndControl, LB_GETTEXT, nIndex, Cast(LPARAM,  @nBuffer(0))) = LB_ERR Then
         Return ""
      Else
       
         Return *CPtr(WString ptr,@nBuffer(0))
      End If
   Else
      Return ""
   End If
   
   
End Function

