|
-
Nov 5th, 1999, 09:22 AM
#1
Thread Starter
Member
First off your going to tell me to use the LBItemFromPT() api in comctl, but i cant, then your going to say to use the LB_ITEMFROMPT flag in a Sendmessage. I cant do that either. 1 simple reason, i draw the listbox myself with a CreateWindowEx... Neither of those methods seem to work. i dont see why they dont. but they dont. so does anyone know how i can do it this way?
-
Nov 5th, 1999, 07:41 PM
#2
Guru
This should work:
Code:
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function LBItemFromPT Lib "comctl32" (ByVal hWndListBox As Long, PT As POINTAPI, ByVal bAutoScroll As Long) As Long
FOLLOWING CODE IS IN WHATEVER EVENT
Dim PT As POINTAPI, lResult As Long, hWndListBox As Long
hWndListBox = CreateWindowEx(Whatever)
PT.X = X_Coordinate
PT.Y = Y_Coordinate
lResult = LBItemFromPt(hWndListBox, PT, False)
------------------
Yonatan
Teenage Programmer
E-Mail: [email protected]
ICQ: 19552879
-
Nov 6th, 1999, 12:11 PM
#3
Thread Starter
Member
Ive tried that already, and the LBItemFromPT just wont work unless i just drag a listbox from the toolbox onto the form, on amy dynamically crated one, it wont work for me
-
Nov 6th, 1999, 12:15 PM
#4
This worked for me:
In a Module..
Code:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const WM_MOUSEMOVE = &H200
Public Const WS_EX_CLIENTEDGE = 512
Public Const GWL_WNDPROC = (-4)
Public Const WS_CHILD = &H40000000
Public Const WS_VSCROLL = &H200000
Public Const WS_VISIBLE = &H10000000
Public Const LB_ADDSTRING = &H180
Public Const LB_GETTEXT = &H189
Public Const LB_ITEMFROMPOINT = &H1A9
Public lPrevWnd As Long
Public lListHwnd As Long
Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim sItem As String
Dim iIndex As Integer
If Msg = WM_MOUSEMOVE Then
sItem = Space(255)
iIndex = SendMessage(lListHwnd, LB_ITEMFROMPOINT, 0&, ByVal lParam) And &HFF
Form1.Text1 = Left(sItem, SendMessage(lListHwnd, LB_GETTEXT, iIndex, ByVal sItem))
End If
WindowProc = CallWindowProc(lPrevWnd, hwnd, Msg, wParam, lParam)
End Function
In a Form with a Textbox on it..
Code:
Private Sub Form_Load()
Dim I As Integer
lListHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "Listbox", "List1", WS_VISIBLE Or WS_CHILD Or WS_VSCROLL, 10, 10, 100, 100, hwnd, 0, App.hInstance, ByVal 0&)
lPrevWnd = SetWindowLong(lListHwnd, GWL_WNDPROC, AddressOf WindowProc)
For I = 1 To 100
Call SendMessage(lListHwnd, LB_ADDSTRING, 0&, ByVal "Item" & I)
Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SetWindowLong(lListHwnd, GWL_WNDPROC, lPrevWnd)
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
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
|