Pcsm
07-13-2011, 01:32 PM
In vb6 its work fine, but in VBA the hWnd i get errror "method not find".
Any idea how to solve de problem?
Option Explicit
Private Declare Function LBItemFromPt Lib "comctl32.dll" (ByVal hLB As Long, ByVal ptx As Integer, ByVal pty As Integer, ByVal bAutoScroll As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private tPos As POINTAPI
Private Const LB_SETSEL = &H185&
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
ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim index As Long
Call SendMessage(Listbox1.hWnd, LB_SETSEL, False, ByVal -1)
GetCursorPos tPos
index = LBItemFromPt(Listbox1.hWnd, tPos.X, tPos.Y, 0)
Call SendMessage(Listbox1.hWnd, LB_SETSEL, True, ByVal index)
End Sub
Private Sub Form_Load()
Listbox1.AddItem "1"
Listbox1.AddItem "2"
Listbox1.AddItem "3"
End Sub
Any idea how to solve de problem?
Option Explicit
Private Declare Function LBItemFromPt Lib "comctl32.dll" (ByVal hLB As Long, ByVal ptx As Integer, ByVal pty As Integer, ByVal bAutoScroll As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private tPos As POINTAPI
Private Const LB_SETSEL = &H185&
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
ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim index As Long
Call SendMessage(Listbox1.hWnd, LB_SETSEL, False, ByVal -1)
GetCursorPos tPos
index = LBItemFromPt(Listbox1.hWnd, tPos.X, tPos.Y, 0)
Call SendMessage(Listbox1.hWnd, LB_SETSEL, True, ByVal index)
End Sub
Private Sub Form_Load()
Listbox1.AddItem "1"
Listbox1.AddItem "2"
Listbox1.AddItem "3"
End Sub