[API]
LVITEM
SendMessageA
SendMessageW

[INCLUDE]
ListView_Item_Count
Unicode

[CODE]
Public Sub ListView_Item_SelectInvert(ByVal hWndListView As Long)
  Dim xLong1 As Long
  Dim xType1 As LVITEM
   
  xType1.stateMask = &H2&
  If IsUnicode Then
    For xLong1 = 0& To ListView_Item_Count(hWndListView) - 1&
      If (SendMessageW(hWndListView, &H102C&, xLong1, ByVal &H2&) = &H2&) Then
        xType1.state = &H0&
        Else
        xType1.state = &H2&
        End If
      Call SendMessageW(hWndListView, &H102B&, xLong1, xType1)
      Next
    Else
    For xLong1 = 0& To ListView_Item_Count(hWndListView) - 1&
      If (SendMessageA(hWndListView, &H102C&, xLong1, ByVal &H2&) = &H2&) Then
        xType1.state = &H0&
        Else
        xType1.state = &H2&
        End If
      Call SendMessageA(hWndListView, &H102B&, xLong1, xType1)
      Next
    End If
  End Sub