|
-
Aug 14th, 2001, 07:07 AM
#1
HitTest property for a ListBox?????
Hi
Is there anyway of finding out from the x& y co-ord's of a point the position of it in terms of listindex for a listbox. If the user drags something over the listbox is it possible to insert the data in between the 2 items? Something like the HitTest property which other controls have.
Appi
-
Aug 14th, 2001, 07:32 AM
#2
Addicted Member
Do you have Microsoft Windows Common controls??
If so you can use a ListView control with the style set to list.
This control supports hittest functionality.
Code:
Private Sub ListView1_DragDrop(Source As Control, x As Single, y As Single)
MsgBox ListView1.HitTest(x, y)
End Sub
HTH
G
-
Aug 14th, 2001, 06:03 PM
#3
Fanatic Member
VB Code:
'in a module
Option Explicit
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const LB_ITEMFROMPOINT As Long = &H1A9
Public Function MakeLong(ByVal intLow As Integer, ByVal intHigh As Integer) As Long
Dim strLow As String
strLow = "0000"
'format the low word as a 4 digit hex string
Mid$(strLow, 5 - Len(Hex$(intLow))) = Hex$(intLow)
'return the new long
MakeLong = CLng("&H" & Hex$(intHigh) & strLow)
End Function
Public Function IndexFromXY(ByVal hWndListBox As Long, ByVal X As Single, ByVal Y As Single) As Integer
Dim lngXY As Long
'put the X,Y position (in pixels) into a long as the function expects
lngXY = MakeLong(CInt(X \ Screen.TwipsPerPixelX), CInt(Y \ Screen.TwipsPerPixelY))
'get the index. the low word of the return is the closest item
'in the listbox, but only the low word is important
IndexFromXY = SendMessage(hWndListBox, LB_ITEMFROMPOINT, 0, lngXY) And &HFFFF
End Function
'usage
Private Sub lstItems_DragDrop(Source As Control, X As Single, Y As Single)
Dim intDropIndex As Integer
intDropIndex = IndexFromXY(lstItems.hWnd, X, Y)
End Sub
Last edited by Kaverin; Aug 14th, 2001 at 06:07 PM.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|