Results 1 to 3 of 3

Thread: Send string to another application?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    10
    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

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    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
    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
    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    10

    ...

    hi,

    Thanks for your answer! i will try it :-)

    Bye

    Martin Fleck (german)


    http://pages.hotbot.com/current/mfleck

Posting Permissions

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



Click Here to Expand Forum to Full Width