|
Добавьте на форму 2 ListBox, 1 ComboBox и 2 CommandButton Private Declare Function SendMessageStr Lib "user32"
Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As
Long, ByVal lParam As String) As Long
Private Declare Function SendMessageLong Lib "user32" Alias
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long,
ByVal lParam As Long) As Long
Private Sub Command1_Click()
Dim success As Long
success = CopyListToList(List1, List2)
End Sub
Private Sub Command2_Click()
Dim success As Long
success = CopyListToCombo(List1, Combo1)
If success Then Combo1.ListIndex = 0
End Sub
Private Function CopyListToList(source As ListBox, target As ListBox) As Long
Dim c As Long
Const LB_GETCOUNT = &H18B
Const LB_GETTEXT = &H189
Const LB_ADDSTRING = &H180
Dim numitems As Long
Dim sItemText As String * 255
numitems = SendMessageLong(source.hWnd, LB_GETCOUNT, 0&, 0&)
If numitems > 0 Then
For c = 0 To numitems - 1
Call SendMessageStr(source.hWnd, LB_GETTEXT, c, ByVal sItemText)
Call SendMessageStr(target.hWnd, LB_ADDSTRING, 0&, ByVal sItemText)
Next
End If
numitems = SendMessageLong(target.hWnd, LB_GETCOUNT, 0&, 0&)
CopyListToList = numitems
End Function
Private Function CopyListToCombo(source As ListBox, target As ComboBox) As Long
Dim c As Long
Const LB_GETCOUNT = &H18B
Const LB_GETTEXT = &H189
Const CB_GETCOUNT = &H146
Const CB_ADDSTRING = &H143
Dim numitems As Long
Dim sItemText As String * 255
numitems = SendMessageLong(source.hWnd, LB_GETCOUNT, 0&, 0&)
If numitems > 0 Then
For c = 0 To numitems - 1
Call SendMessageStr(source.hWnd, LB_GETTEXT, c, ByVal sItemText)
Call SendMessageStr(target.hWnd, CB_ADDSTRING, 0&, ByVal sItemText)
Next
End If
numitems = SendMessageLong(target.hWnd, CB_GETCOUNT, 0&, 0&)
CopyListToCombo = numitems
End Function
Private Sub Form_Load()
List1.AddItem "1"
List1.AddItem "2"
List1.AddItem "3"
End Sub
|
|