首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

如何读取外程序的listbox的内容 在线

2012-01-30 
怎么读取外程序的listbox的内容 在线怎么读取外程序的listbox的内容在线,先谢谢了[解决办法]在vb里面如何

怎么读取外程序的listbox的内容 在线
怎么读取外程序的listbox的内容   在线,先谢谢了

[解决办法]
在vb里面如何得到外部程序的ListBox内容

以下代码掩饰在得知两个ListBox句柄时,把其中一个里面的内容复制到另外一个里面

DuplicateListBox参数解释:
SourceHwnd=源ListBox句柄(HWnd)
TargetHwnd=目标ListBox句柄(HWnd)
AppendMode=是否对源ListBox的Content进行校验,True就可以了

========================================================================
Private Declare Function SendMessage Lib "user32 " Alias "SendMessageA " (ByVal _
hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function LockWindowUpdate Lib "user32 " (ByVal hwndLock As Long) _
As Long

Const LB_RESETCONTENT = &H184
Const LB_GETCOUNT = &H18B
Const LB_GETTEXT = &H189
Const LB_ADDSTRING = &H180
Const LB_GETITEMDATA = &H199
Const LB_SETITEMDATA = &H19A


Sub DuplicateListBox(SourceHwnd As Long, TargetHwnd As Long, _
Optional AppendMode As Boolean)
Dim index As Long
Dim itmData As Long
Dim numItems As Long
Dim sItemText As String

' prepare the receiving buffer
sItemText = Space$(512)

' temporarily prevent updating
LockWindowUpdate TargetHwnd

' reset target contents, if not in append mode
If Not AppendMode Then
SendMessage TargetHwnd, LB_RESETCONTENT, 0, ByVal 0&
End If

' get the number of items in the source list
numItems = SendMessage(SourceHwnd, LB_GETCOUNT, 0&, ByVal 0&)

For index = 0 To numItems - 1
' get the item text
SendMessage SourceHwnd, LB_GETTEXT, index, ByVal sItemText
' get the item data
itmData = SendMessage(SourceHwnd, LB_GETITEMDATA, index, ByVal 0&)
' add the item text to the target list
SendMessage TargetHwnd, LB_ADDSTRING, 0&, ByVal sItemText
' add the item data to the target list
SendMessage TargetHwnd, LB_SETITEMDATA, index, ByVal itmData
Next

' allow redrawing
LockWindowUpdate 0

End Sub

调用
DuplicateListBox SourceHwnd, TargetHwnd, True


热点排行