[API]
SendMessageW
SendMessageA
LocalFree
LVCOLUMN
LVITEM
InitCommonControlsExType
InitCommonControlsEx

[INCLUDE]
LocalAllocFromString

[CODE]
Public Sub ListView_Header_Add(ByVal hWndListView As Long, ByVal Index As Long, ByVal Text As String, Optional ByVal ImageID As Long = -1&, Optional ByVal Width As Long = -1&, Optional ByVal Alignment As Long)
  Dim xType1 As LVCOLUMN
  
  With xType1
    .pszText = LocalAllocFromString(Text)
    If Not .pszText = 0& Then
      If ImageID = -1& Then
        If Not Alignment = 0& Then
          .fmt = 5&
          .mask = Alignment Or &H8004&
          Else
          .mask = &H4&
          End If
        Else
        .iImage = ImageID
        .mask = &H15&
        .fmt = Alignment Or &H8004&
        End If
      If Not Width = -1& Then
'Debug.Print "HeaderWidth: ", Width
        .mask = .mask Or &H2&
        If Index = 0& Then
          .cx = Width + 20&
          Else
          .cx = Width
          End If
        End If
      If Index = 0& And Not Alignment = 0& Then
        If IsUnicode Then
          If Not SendMessageW(hWndListView, &H1061&, 0&, xType1) = 0& Then
            If Not SendMessageW(hWndListView, &H1061&, 0&, xType1) = 0& Then
              Call SendMessageW(hWndListView, &H101C&, 0&, ByVal 0&)
              End If
            End If
'(LVM_FIRST + 28)
          Else
          If Not SendMessageA(hWndListView, &H101B&, 0&, xType1) = 0& Then
            If Not SendMessageA(hWndListView, &H101B&, 0&, xType1) = 0& Then
              Call SendMessageA(hWndListView, &H101C&, 0&, ByVal 0&)
              End If
            End If
          End If
        ElseIf IsUnicode Then
        Call SendMessageW(hWndListView, &H1061&, Index, xType1)
        Else
        Call SendMessageA(hWndListView, &H101B&, Index, xType1)
        End If
      Call LocalFree(.pszText)
      End If
    End With
  End Sub

Public Function ListView_Item_Add(ByVal hWndListView As Long, ByVal Text As String, Optional ByVal lParam As Long, Optional ByVal ImageID As Long) As Long
  Dim xType1 As LVITEM
  
  With xType1
    .pszText = LocalAllocFromString(Text)
    If Not .pszText = 0& Then
      .mask = &H7&
      .lParam = lParam
      .iImage = ImageID
      .iItem = &H7FFFFFFF
      If IsUnicode Then
        ListView_Item_Add = SendMessageW(hWndListView, &H104D&, 0&, xType1)
        Else
        ListView_Item_Add = SendMessageA(hWndListView, &H1007&, 0&, xType1)
        End If
      Call LocalFree(.pszText)
      End If
    End With
'Debug.Print "ListView_Item_Add; data=" + CStr(lParam)
  End Function