Hallo Leute!
Ich habe Listbox-Einträge mit hilfe eines API-Aufrufes zu finden (wie mehrfahc im Netz gezeigt.
Leider liefert der Sendmessage-Aufruf nichts zurück.
Folgendes habe ich ausprobiert:
Userform1 in UF1 umbenannt.
Folgender Code steht im Modul1:
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetFocus Lib "user32" () As Long
Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Const LB_FINDSTRING = &H18F
Const LB_FINDSTRINGEXACT = &H1A2
Dim LBhWnd As Long, ret As Long
Dim PhWnd As Long, UFhWnd As Long
Sub Init()
UF1.Show vbModeless
UF1.ListBox1.SetFocus
LBhWnd = GetFocus
PhWnd = GetParent(LBhWnd)
UFhWnd = FindWindow(vbNullString, "UserForm1")
UF1.ListBox1.AddItem "aa"
UF1.ListBox1.AddItem "ab"
UF1.ListBox1.AddItem "ac"
UF1.ListBox1.AddItem "ad"
ret = SendMessage(LBhWnd, LB_FINDSTRING, -1, ByVal CStr("ab"))
If ret <> 0 Then
MsgBox "Text gefunden! Eintrag Nr " & ret
End If
end sub
Hat jemand eine Idee, worann es liegen kann?
Mit LB_FINDSTRING ist eine Ähnlichkeitssuche eingestellt.
Darauf kommt es mir letztendlich an, die zu suchenden Werte sich oft nicht enthalten.
Vielen Dank für die Mühe!!
|