0

I have an owner-drawn virtual listview. I set the view to LargeIcon, I set the LargeImageList to the appropriate image list, but when I call LVM_SETICONSPACING, it does not work! That is - it has no effect no matter what values I put in.

I use:

 Const LVM_FIRST As Long = &H1000
 Const LVM_SETICONSPACING As Long = LVM_FIRST + 53
 WinAPI.SendMessage(ListView.Handle, LVM_SETICONSPACING, 0, cy * 65536 + (cx And 65535))

I also tried:

 WinAPI.SendMessage(ListView.Handle, LVM_SETICONSPACING, 0, cy * 65536 + cx)
 WinAPI.SendMessage(ListView.Handle, LVM_SETICONSPACING, 0, cx * 65536 + cy)

All do absolutely nothing no matter what values for cx and cy I use. I tried from small like 10 to big like 400 for both - no difference.

I tried refreshing the list afterwards - no difference. item.bounds remains unchanged, and I have a 30px tall spacing between rows of icons. How do I get rid of that spacing? I also tried variants with Ints and IntPtr-s for SendMessage.

Maybe the issue is that I use Windows 8 64 bit (though program is 32 bit)? Or the fact that in virtual mode, listview ignores this message?

I even checked that the message gets sent by trapping it in WndProc override.

Take 2:

I even tried with IntPtr as some have suggested w/o luck. I also tried all possible values for the both vertical and horizontal spacing of 5: &H50005000, &H00050005, as well as &H5000000050000000, &H0000000500000005. No difference, it is as if it is totally ignored. Maybe LVM_SETICONSPACING has a different value?

Any suggestions would be welcome.

Thank you.

Fit Dev
  • 3,413
  • 3
  • 30
  • 54

1 Answers1

0

Using a bit-wise shift with cx and cy in order to create the correct IntPtr works instead of using multiplication. This method is described in another post.

Private Sub SetImageSpacingForListView(ByVal lView As ListView, ByVal cx As Short, ByVal cy As Short)
  ' http://qdevblog.blogspot.co.uk/2011/11/c-listview-item-spacing.html
  ' http://msdn.microsoft.com/en-us/library/bb761176(VS.85).aspx

  Dim LVM_FIRST As Integer = &H1000
  Dim LVM_SETICONSPACING As Integer = LVM_FIRST + 53
  WinAPI.SendMessage(lView.Handle, LVM_SETICONSPACING, IntPtr.Zero, CType(MakeLong(cx, cy), IntPtr))
End Sub

Private Function MakeLong(ByVal lowPart As Short, ByVal highPart As Short) As Integer
  Return CType(CType(lowPart, UShort) Or CType(highPart << 16, UInteger), Integer)
End Function
Community
  • 1
  • 1
gotorg
  • 147
  • 1
  • 10
  • Thanks. Tried that but it does not work on Windows 8.1 x64. Not sure about other OS-s. It does not seem to do anything at all no matter what values I use and whether I convert to IntPtr or not. – Fit Dev Mar 14 '14 at 12:49