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(Source As ListBox, Target As ListBox, _ Optional AppendMode As Boolean) Dim index As Long Dim itmData As Long Dim numItems As Long Dim sItemText As String sItemText = Space$(512) LockWindowUpdate Target.hWnd If Not AppendMode Then SendMessage Target.hWnd, LB_RESETCONTENT, 0, ByVal 0& End If
numItems = SendMessage(Source.hWnd, LB_GETCOUNT, 0&, ByVal 0&) For index = 0 To numItems - 1 SendMessage Source.hWnd, LB_GETTEXT, index, ByVal sItemText itmData = SendMessage(Source.hWnd, LB_GETITEMDATA, index, ByVal 0&) SendMessage Target.hWnd, LB_ADDSTRING, 0&, ByVal sItemText SendMessage Target.hWnd, LB_SETITEMDATA, index, ByVal itmData Next LockWindowUpdate 0 End Sub |