Just wondering if anyone has any code to hand to pull the data from another application's listbox or RTB ?
Printable View
Just wondering if anyone has any code to hand to pull the data from another application's listbox or RTB ?
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
VB Code:
'\\ From the [b]ApiComboControl[/b] class: Public Enum enComboBoxMessages CB_ADDSTRING = &H143 CB_DELETESTRING = &H144 CB_DIR = &H145 CB_FINDSTRING = &H14C CB_FINDSTRINGEXACT = &H158 CB_GETCOUNT = &H146 CB_GETCURSEL = &H147 CB_GETDROPPEDCONTROLRECT = &H152 CB_GETEDITSEL = &H140 CB_GETLBTEXT = &H148 CB_GETLBTEXTLEN = &H149 CB_INSERTSTRING = &H14A CB_LIMITTEXT = &H141 CB_RESETCONTENT = &H14B CB_SELECTSTRING = &H14D CB_SETCURSEL = &H14E CB_SETEDITSEL = &H142 CB_SHOWDROPDOWN = &H14F CB_GETITEMDATA = &H150 CB_SETITEMDATA = &H151 CB_SETITEMHEIGHT = &H153 CB_GETITEMHEIGHT = &H154 CB_SETEXTENDEDUI = &H155 CB_GETEXTENDEDUI = &H156 CB_GETDROPPEDSTATE = &H157 CB_SETLOCALE = &H159 CB_GETLOCALE = &H15A CB_GETTOPINDEX = &H15B CB_SETTOPINDEX = &H15C CB_GETHORIZONTALEXTENT = &H15D CB_SETHORIZONTALEXTENT = &H15E CB_GETDROPPEDWIDTH = &H15F CB_SETDROPPEDWIDTH = &H160 CB_INITSTORAGE = &H161 CB_MULTIPLEADDSTRING = &H163 End Enum 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 Public Property Get List(ByVal Index As Long) As String If mHWND <> 0 Then Dim lLen As String Dim sList As String lLen = SendMessageLong(mHWND, CB_GETLBTEXTLEN, Index, 0) If lLen > 0 Then sList = String$(lLen, 0) Call SendMessageLong(mHWND, CB_GETLBTEXT, Index, StrPtr(sList)) If Err.LastDllError Then ReportError Err.LastDllError, CLSNAME & ":List", GetLastSystemError End If End If End If End Property
Speak of the devil.. there is its, you mention the acronym API and *poof* it appears!
-mcd
I tried that code and cant seem to get it to work, when I used it, sList comes back as "?????????"
any ideas?
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_.
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?
No, you cant just change the constant name. you need to also change the value.
VB Code:
Private Const LB_GETCOUNT As Long = &H18B Private Const LB_GETCURSEL As Long = &H188 Private Const LB_GETTEXT As Long = &H189 Private Const LB_GETTEXTLEN As Long = &H18A 'Etc.
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.
You need to make sure your using the correct window handle for the your listbox
VB Code:
lLen = SendMessageLong([color=red]mHWND[/color], LB_GETCOUNT, Index, 0)
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.
VB Code:
Public Const LB_GETCOUNT = &H18B Public Const LB_GETTEXT = &H189 window = FindWindow("classname", vbNullString) combobox = FindWindowEx(window, 0&, "ComboBox", vbNullString) If combobox <> 0 Then Dim lLen As String Dim sList As String Dim numItems As Long lLen = SendMessageLong(combobox, LB_GETCOUNT, Index, 0) If lLen > 0 Then sList = String$(lLen, 0) Call SendMessageLong(combobox, LB_GETTEXT, Index, StrPtr(sList)) End If End If
This is my code , and lLen always comes up as 0, then sList is blank.
it is a combobox , so back to using the CB ones..
Whats index for in this code?
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
I PM'd you.
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