СообЧа > База Знаний > Программирование > Visual Basic > Формы и элементы управления

Вопрос

Как добавлять в листбокс строки с помощью АПИ?

Ответ

Этот код быстро скопирует один листбокс в другой:

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 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

Наметкин Андрей



Copyright © 2000-2004 Сообщество Чайников
Контактная информация