PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
SendMessage - LB_ITEMFROMPOINT Always returns the first item on the list!!!-VBForums
Results 1 to 3 of 3

Thread: SendMessage - LB_ITEMFROMPOINT Always returns the first item on the list!!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Posts
    28

    SendMessage - LB_ITEMFROMPOINT Always returns the first item on the list!!!

    I use the following procedure with a ListBox called "lstFolders" to show a ToolTipText with the name of the item that the mouse's pointer is pointing, but it always returns the first item's name. Can you tell me why?
    BTW I use "Option Base 1", don't know if it has anything to do with it.
    Code:
    Option Explicit
    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 '
    Private Const LB_ITEMFROMPOINT = &H1A9
    
    Private Sub lstFolders_MouseMove(Button As Integer, 
    
    Shift As Integer, X As Single, Y As Single)
    Dim lngPos As Long
    Dim XX As Long
    Dim YY As Long
    Dim i As Integer
    
        XX = CLng(X / Screen.TwipsPerPixelX)
        YY = CLng(Y / Screen.TwipsPerPixelY)
        lngPos = SendMessage(lstFolders.hwnd, LB_ITEMFROMPOINT, 0, ByVal ((YY * 65536) + XX))
         
        If lngPos < lstFolders.ListCount And lngPos > -1 Then
            lstFolders.ToolTipText = lstFolders.List(lngPos)
        End If
    
    End Sub

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Strange, this works for me:
    VB Code:
    1. Option Explicit
    2. Option Base 1 Rem <-----
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    4. ByVal wParam As Long, lParam As Any) As Long
    5. Private Const LB_ITEMFROMPOINT = &H1A9
    6.  
    7. Private Sub Command1_Click()
    8. Dim i As Integer
    9. With lstFolders
    10.     For i = 0 To 40
    11.         .AddItem "BLA" & i
    12.     Next i
    13. End With
    14. End Sub
    15.  
    16. Private Sub lstFolders_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    17. Dim lngPos As Long
    18. Dim XX As Long
    19. Dim YY As Long
    20. Dim i As Integer
    21.  
    22.     XX = CLng(X / Screen.TwipsPerPixelX)
    23.     YY = CLng(Y / Screen.TwipsPerPixelY)
    24.     lngPos = SendMessage(lstFolders.hwnd, LB_ITEMFROMPOINT, 0, ByVal ((YY * 65536) + XX))
    25.      
    26.     If lngPos < lstFolders.ListCount And lngPos > -1 Then
    27.         lstFolders.ToolTipText = lstFolders.List(lngPos)
    28.     End If
    29.  
    30. End Sub
    I'd say it could have to do with your screen resolution. Mine is 1280x1024, and it returns the correct item no matter how close to the edge the mouse is. Since I'm not exactly an expert in that area, I'd just have to assume the "65536" value needs changing according to your resolution.

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width