在VBA中获得了listBox的句柄, 如何才能获得ListItem ?
在获得了listbox控件句柄后, 想继续读取列表信息, 用如下程序未成功, 请帮助看看错在什么地方?Const LB_GETCOUNT = &H18B
Sub GetListItem(ByVal childWnd As Long, ByRef item() As String)
Dim Count As Long, idx As Long, i As Long
Count = SendMessage(childWnd, LB_GETCOUNT, ByVal 0&, ByVal 0&)
For i = 0 To Count - 1
ReDim Preserve item(i)
item(i) = String(255, Chr(0))
SendMessage childWnd, LB_GETTEXT, ByVal i, ByVal item(i)
item(i) = Left(item(i), InStr(item(i), Chr(0)) - 1)
Next i
End Sub
childWnd 是ListBox 的句柄
item() 是Listcount 的信息
--------------------编程问答-------------------- 这个我会,qq:2605961812 --------------------编程问答--------------------
'┏〓〓〓〓〓〓〓〓〓 GetAllListItem,start 〓〓〓〓〓〓〓〓〓┓--------------------编程问答-------------------- 楼上的朋友,谢谢你的指导。
'[简介]:
'API方式获取所有LISTBOX的项目值
Function GetAllListItem(Hwnd1 As Long)
'VB源码,帮你写函数,帮你写代码,帮你写模块,帮你设计软件
'--需要什么函数或功能,可以联系我。
'版权所有,请保留作者信息.QQ:2605961812
'如需商业用途请联系作者
Dim Counts As Long, UB As Long
Counts = SendMessage(Hwnd1, LB_GETCOUNT, 0, 0)
If Counts = 0 Then Exit Function
Dim Sz
UB = Counts - 1
ReDim Sz(UB)
Dim S As String
Dim ListIndex As Long
For ListIndex = 0 To UB
S = String$(255, 0)
SendMessageByString& Hwnd1, LB_GETTEXT, ListIndex, S
S = Left$(S, InStr(1, S, Chr$(0)) - 1)
Sz(ListIndex) = S
Next
GetAllListItem = Sz
End Function
'┗〓〓〓〓〓〓〓〓〓 GetAllListItem,end 〓〓〓〓〓〓〓〓〓┛
待我再学习后,再向你请教。 --------------------编程问答-------------------- '┏〓〓〓〓〓〓〓〓〓 GetAllListItem,start 〓〓〓〓〓〓〓〓〓┓
'[简介]:
'API方式获取所有LISTBOX的项目值
Function GetAllListItem(Hwnd1 As Long)
'VB源码,帮你写函数,帮你写代码,帮你写模块,帮你设计软件
'--需要什么函数或功能,可以联系我。
'版权所有,请保留作者信息.QQ:2605961812
'如需商业用途请联系作者
Dim Counts As Long, UB As Long
Counts = SendMessage(Hwnd1, LB_GETCOUNT, 0, 0)
If Counts = 0 Then Exit Function
Dim Sz
UB = Counts - 1
ReDim Sz(UB)
Dim S As String
Dim ListIndex As Long
For ListIndex = 0 To UB
S = String$(255, 0)
SendMessageByString& Hwnd1, LB_GETTEXT, ListIndex, S
S = Left$(S, InStr(1, S, Chr$(0)) - 1)
Sz(ListIndex) = S
Next
GetAllListItem = Sz
End Function
'┗〓〓〓〓〓〓〓〓〓 GetAllListItem,end 〓〓〓〓〓〓〓〓〓┛
补充:VB , API