Results 1 to 17 of 17

Thread: Reading information from another application's listbox

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Reading information from another application's listbox

    Just wondering if anyone has any code to hand to pull the data from another application's listbox or RTB ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  2. #2
    Hyperactive Member MetallicaD's Avatar
    Join Date
    Feb 2001
    Location
    Tallahassee, FL
    Posts
    488
    Im sure there is an API to do this.. you probably just need a handle to the other app.. check out the API board

    -mcd
    [vbcode]
    '*****************************
    MsgBox "MCD :: [email protected]", vbInformation + vbOKOnly, "User"
    '*****************************
    [/vbcode]

  3. #3
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    VB Code:
    1. '\\ From the [b]ApiComboControl[/b] class:
    2. Public Enum enComboBoxMessages
    3.     CB_ADDSTRING = &H143
    4.     CB_DELETESTRING = &H144
    5.     CB_DIR = &H145
    6.     CB_FINDSTRING = &H14C
    7.     CB_FINDSTRINGEXACT = &H158
    8.     CB_GETCOUNT = &H146
    9.     CB_GETCURSEL = &H147
    10.     CB_GETDROPPEDCONTROLRECT = &H152
    11.     CB_GETEDITSEL = &H140
    12.     CB_GETLBTEXT = &H148
    13.     CB_GETLBTEXTLEN = &H149
    14.     CB_INSERTSTRING = &H14A
    15.     CB_LIMITTEXT = &H141
    16.     CB_RESETCONTENT = &H14B
    17.     CB_SELECTSTRING = &H14D
    18.     CB_SETCURSEL = &H14E
    19.     CB_SETEDITSEL = &H142
    20.     CB_SHOWDROPDOWN = &H14F
    21.     CB_GETITEMDATA = &H150
    22.     CB_SETITEMDATA = &H151
    23.     CB_SETITEMHEIGHT = &H153
    24.     CB_GETITEMHEIGHT = &H154
    25.     CB_SETEXTENDEDUI = &H155
    26.     CB_GETEXTENDEDUI = &H156
    27.     CB_GETDROPPEDSTATE = &H157
    28.     CB_SETLOCALE = &H159
    29.     CB_GETLOCALE = &H15A
    30.     CB_GETTOPINDEX = &H15B
    31.     CB_SETTOPINDEX = &H15C
    32.     CB_GETHORIZONTALEXTENT = &H15D
    33.     CB_SETHORIZONTALEXTENT = &H15E
    34.     CB_GETDROPPEDWIDTH = &H15F
    35.     CB_SETDROPPEDWIDTH = &H160
    36.     CB_INITSTORAGE = &H161
    37.     CB_MULTIPLEADDSTRING = &H163
    38. End Enum
    39.  
    40. Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As enComboBoxMessages, ByVal wParam As Long, ByVal lParam As Long) As Long
    41.  
    42. Public Property Get List(ByVal Index As Long) As String
    43.  
    44. If mHWND <> 0 Then
    45.     Dim lLen As String
    46.     Dim sList As String
    47.     lLen = SendMessageLong(mHWND, CB_GETLBTEXTLEN, Index, 0)
    48.     If lLen > 0 Then
    49.         sList = String$(lLen, 0)
    50.         Call SendMessageLong(mHWND, CB_GETLBTEXT, Index, StrPtr(sList))
    51.         If Err.LastDllError Then
    52.             ReportError Err.LastDllError, CLSNAME & ":List", GetLastSystemError
    53.         End If
    54.     End If
    55. End If
    56.  
    57. End Property
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  4. #4
    Hyperactive Member MetallicaD's Avatar
    Join Date
    Feb 2001
    Location
    Tallahassee, FL
    Posts
    488
    Speak of the devil.. there is its, you mention the acronym API and *poof* it appears!

    -mcd
    [vbcode]
    '*****************************
    MsgBox "MCD :: [email protected]", vbInformation + vbOKOnly, "User"
    '*****************************
    [/vbcode]

  5. #5
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    399

    Re: Reading information from another application's listbox

    I tried that code and cant seem to get it to work, when I used it, sList comes back as "?????????"


    any ideas?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Reading information from another application's listbox

    Thats because the example is for a Combo Box control and not a Listbox control. Just use the constants from the api guide that start with LB_.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    399

    Re: Reading information from another application's listbox

    What LB things could I use?

    for GETLBTEXTLEN I used LB_GETCOUNT
    and for GETLBTEXT I used LB_GETTEXT
    and it doesnt work, for slist I get 1 character reply now, and for ILen I get blank, before with GETLBTEXTLEN I would get an integer value.

    any ideas?

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Reading information from another application's listbox

    No, you cant just change the constant name. you need to also change the value.


    VB Code:
    1. Private Const LB_GETCOUNT As Long = &H18B
    2. Private Const LB_GETCURSEL As Long = &H188
    3. Private Const LB_GETTEXT As Long = &H189
    4. Private Const LB_GETTEXTLEN As Long = &H18A
    5.  
    6. 'Etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    399

    Re: Reading information from another application's listbox

    Ihave those consts, I was asking if I was using the right ones. I already had all the values changed ,however it still isnt working.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Reading information from another application's listbox

    You need to make sure your using the correct window handle for the your listbox
    VB Code:
    1. lLen = SendMessageLong([color=red]mHWND[/color], LB_GETCOUNT, Index, 0)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    399

    Re: Reading information from another application's listbox

    I already said I switched those and it isnt working.

    Why do you think I am suppost to use Listbox controls?
    API spy says it is a combobox.

  12. #12
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    399

    Re: Reading information from another application's listbox

    VB Code:
    1. Public Const LB_GETCOUNT = &H18B
    2. Public Const LB_GETTEXT = &H189
    3.  
    4.  
    5. window = FindWindow("classname", vbNullString)
    6. combobox = FindWindowEx(window, 0&, "ComboBox", vbNullString)
    7. If combobox <> 0 Then
    8.     Dim lLen As String
    9.     Dim sList As String
    10.     Dim numItems As Long
    11.     lLen = SendMessageLong(combobox, LB_GETCOUNT, Index, 0)
    12.     If lLen > 0 Then
    13.         sList = String$(lLen, 0)
    14.         Call SendMessageLong(combobox, LB_GETTEXT, Index, StrPtr(sList))
    15.     End If
    16. End If


    This is my code , and lLen always comes up as 0, then sList is blank.

  13. #13
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    399

    Re: Reading information from another application's listbox

    it is a combobox , so back to using the CB ones..

  14. #14
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    399

    Re: Reading information from another application's listbox

    Whats index for in this code?

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Reading information from another application's listbox

    Well seeing how this thread was on how to read a Listbox control in another program. You never said you were using a combo box.
    You never posted any code until I PM'd you about it either.

    I understand your frustration but I'm out of time tonight.

    Sorry and thanks for the negative Rep point when I was just trying to help you.
    Robert
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    399

    Re: Reading information from another application's listbox

    I PM'd you.

  17. #17
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    399

    Re: Reading information from another application's listbox

    Sorry RedDog, I did eventually figure it out (well the jist of it), I was unclear and you misunderstood me, which in the end actually helped. I have a better understanding of it now.

    Thanks
    Last edited by manavo11; Jun 9th, 2005 at 04:03 PM. Reason: Profanity

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