PDA

Click to See Complete Forum and Search --> : sendmessage: not on correct line???


c@lle
Dec 12th, 2000, 09:26 AM
Option Explicit
Private Declare Function sendMessageByString& Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String)

Private Sub Command1_Click()
Dim lngEntryNum As Long
Dim strTxtToFind As String

lngEntryNum = sendMessageByString(List1.hwnd, &H18C, 0, "abc")

End Sub

Private Sub Form_Load()
List1.AddItem "abc"
List1.AddItem "abcd"
List1.AddItem "abcd d"
List1.AddItem "abdd e"
List1.AddItem "abd"
List1.AddItem "abdec"
End Sub


when I use this code, he selects the second line, instead of the first. Why???

Jop
Dec 12th, 2000, 11:14 AM
Ouch that hurts my eyes :eek:



lngEntryNum = sendMessageByString(List1.hwnd, &H18C, 0, "abc")



neeevvvvvvver :rolleyes: use that kindof hex values ;)

use constants instead.


like this:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F



I think it's selecting the first item because you did:


lngEntryNum = sendMessageByString(List1.hwnd, &H18C, 0, "abc")



and that should be:



lngEntryNum = sendMessageByString(List1.hwnd, LB_FINDSTRING, -1, "abc")



so with all code that would make:


Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F

Private Sub Command1_Click()
Dim lngEntryNum As Long
Dim strTxtToFind As String

lngEntryNum = sendMessage(List1.hwnd, LB_FINDSTRING, -1, "abc")



End Sub

Private Sub Form_Load()
List1.AddItem "abc"
List1.AddItem "abcd"
List1.AddItem "abcd d"
List1.AddItem "abdd e"
List1.AddItem "abd"
List1.AddItem "abdec"
End Sub


Did that fixed the prob?

Mad Compie
Dec 12th, 2000, 01:44 PM
&H18C is the value for the message LB_SELECTSTRING

c@lle
Dec 13th, 2000, 01:59 AM
yes, it is working. Thanks a lot Jop & Mad Compie.

Jop
Dec 13th, 2000, 08:06 AM
Originally posted by Mad Compie
&H18C is the value for the message LB_SELECTSTRING

OOPS wasn't paying attention :o
sorry, but fine it's working :)