hi,
how can i send a string to another application“s listbox? ist that possible? where can i find samples or anything else?
Thanks.
Martin Fleck (german)
http://pages.hotbot.com/current/mfleck
Printable View
hi,
how can i send a string to another application“s listbox? ist that possible? where can i find samples or anything else?
Thanks.
Martin Fleck (german)
http://pages.hotbot.com/current/mfleck
Sure, you just need to know the Window Handle of the Listbox then you can use the SendMessage API with the LB_ADDSTRING Constant, ie.
Code:'---[Module Code]---
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private lListBoxHwnd As Long
Private Function EnumProc(ByVal Hwnd As Long, ByVal lParam As Long) As Long
Static lInstances As Long
Dim sClass As String
If Hwnd Then
sClass = Space(255)
sClass = Left$(sClass, GetClassName(Hwnd, sClass, 255))
If InStr(LCase(sClass), "listbox") Then
If lListBoxHwnd = 0 Then lInstances = 0
lInstances = lInstances + 1
lListBoxHwnd = Hwnd
If lInstances = lParam Then Exit Function
End If
End If
EnumProc = Hwnd
End Function
Public Function FindListbox(ByVal Hwnd As Long, Optional ByVal Instance As Long = 1) As Long
lListBoxHwnd = 0
Call EnumChildWindows(Hwnd, AddressOf EnumProc, Instance)
FindListbox = lListBoxHwnd
End Function
Where lAppHwnd is the Window Handle of the Form containing the Listbox, the FindListbox function I wrote will enumerate all child Windows on the Form and find any that are Listboxes, if there are multiple Listboxes on the Form you can specify an Instance to determine which one has its handle returned.Code:'---[Form Code]---
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_ADDSTRING = &H180
Private Sub Command1_Click()
Dim lHwnd As Long
Dim sText As String
sText = Text1
lHwnd = FindListbox(lAppHwnd)
If lHwnd Then SendMessage lHwnd, LB_ADDSTRING, 0&, ByVal sText
End Sub
hi,
Thanks for your answer! i will try it :-)
Bye
Martin Fleck (german)
http://pages.hotbot.com/current/mfleck