Results 1 to 1 of 1

Thread: [VB6] Partial String Search for ImageCombo

  1. #1
    Lively Member
    Join Date
    Jul 10
    Posts
    89

    [VB6] Partial String Search for ImageCombo

    If anyone has worked with the ImageCombo control, you'll notice that CB_FINDSTRING does not work, even when sent to the underlying ComboBox control (via CBEM_GETCOMBOCONTROL). So the search much be conducted manually.

    -This returns the zero-based index of the result; not the full string (where to make the small change to return that instead is noted)

    VB Code:
    1. 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
    2.  
    3.  
    4. Public Const CB_GETLBTEXT = &H148
    5. Public Const CB_GETLBTEXTLEN = &H149
    6. Public Const CB_GETCOUNT = &H146
    7.  
    8.  
    9. Public Function CBX_PartialSearch(hWnd As Long, ss As String) As Long
    10. 'ComboBoxEx (aka ImageCombo) only supports CB_FINDSTRINGEXACT
    11. 'So searching for a partial string must be done manually
    12. Dim sBuf As String
    13. Dim lCnt As Long
    14. Dim lLen As Long
    15. Dim i As Long
    16.  
    17. lCnt = SendMessage(hWnd, CB_GETCOUNT, 0, ByVal 0&)
    18.  
    19. For i = 0 To lCnt - 1
    20.     lLen = SendMessage(hWnd, CB_GETLBTEXTLEN, i, ByVal 0&)
    21.     sBuf = Space$(lLen)
    22.     Call SendMessage(hWnd, CB_GETLBTEXT, i, ByVal sBuf)
    23.     If InStr(sBuf, ss) Then
    24.         CBX_PartialSearch = i 'return sBuf if you want the full item instead of its index
    25.         Exit Function
    26.     End If
    27. Next i
    28.  
    29. End Function
    Last edited by fafalone; May 21st, 2012 at 08:19 PM. Reason: derp

Posting Permissions

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