Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

GetText from ListBox


  • Please log in to reply
8 replies to this topic
David Andersen
  • Guests
  • Last active:
  • Joined: --
I really need to read the text in a ListBox. My script is as follows:
#x::
SendMessage, 0x189, 2, 0, WindowsForms10.LISTBOX.app.0.378734a1, Form1
if ErrorLevel <> FAIL
{
MsgBox, %ErrorLevel%
}

Where 0x189 refers to the following MSDN function:
http://msdn.microsof... ... ettext.asp

at least according to http://www.codeguru.... ... .php/c2771

Anyways... My problem is that this returns the length of the string in the listbox (this is in accordance with the description of LB_GETTEXT on MSDN. My quesiton is how I could retreave the content that lParam is pointing at after this sendmessage function.

The following is a link to an .exe file that made in Visual Studio 2005 beta 2 (hope it works for you), containing the listbox that I am trying to retreave the text from. http://www.translati...ds.com/demo.exe.

Thanks

  • Guests
  • Last active:
  • Joined: --
Sorry. The forum platform thought that it should include the dot at the end of my link. The following is a working link.

http://www.translati...ds.com/demo.exe

Thanks

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

I really need to read the text in a ListBox.

Have you tried "ControlGet, List"? This is a relatively recent feature that gets a complete list of items from a ListBox, ComboBox, or DropDownList.

David Andersen
  • Guests
  • Last active:
  • Joined: --
Thanks for the replay, Chris.

I have tried the following script:
ControlGet, List, List,, WindowsForms10.LISTBOX.app.0.378734a1, Form1
Loop, Parse, List, `n
{
MsgBox Item number %A_Index% is %A_LoopField%.
}

Unfortunatelly, I did not receive any output at all.

While I got a message box saying "5" with the following script:
SendMessage, 0x189, 2, 0, WindowsForms10.LISTBOX.app.0.378734a1, Form1
if ErrorLevel <> FAIL
{
MsgBox, %ErrorLevel%
}

5 represents the number of characters in this entry in the list.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
ControlGet is only designed to work with standard ListBoxes and ComboBoxes. Yours control seems like a non-standard (custom) control, which might explain why it doesn't work.

Although I'm all out of ideas, I hope you find a solution or that someone else comes along who knows something.

David Andersen
  • Guests
  • Last active:
  • Joined: --
I understand. The control that I am using is the standard one used by Visual Studio 2005 (although, I am using the beta 2 version).

Although I don't know C++ I found the method that would need some adjustments to make it possible to receive the text. Its name is ScriptSendMessage and it is located in Script2.cpp. This method uses the MSDN method SendMessageTimeout (http://msdn.microsoft.com/library/defau ... ettext.asp).

Are there any C++ experts out there that knows how to implement this?

Thanks a lot in advance.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I don't see how any internal changes to SendMessage would help in this case. The "ControlGet List" method I mentioned
earlier already uses LB_GETTEXT internally. If it fails to work on a custom ListBox, you would have to find out what
messages to send to that particular type of ListBox to get the text out of it.

Microsoft Active Accessibility might be able to extract text from many types of custom controls, but I don't know much
else about it yet.

David Andersen
  • Members
  • 140 posts
  • Last active: Jun 28 2011 04:54 PM
  • Joined: 15 Jul 2005
Thank you a lot for your help. I have sent you 10 dollars to your email address to show my appreciation.

I have a far more general question now. Is it in principle possible to extract the text from any listbox or combobox? I understand that i.e. Java programs are build up in a totally different way, so my question is just about the programs that show up as listboxes in AU3_Spy.

I really need to read text from a range of listboxes where the one at http://www.translati...ds.com/demo.exe is an example of one of them. I think that all the listboxes I want to read from have been programmed in Visual Studio.

I have also thought about using OCR technology to "read" the text off the screen, but this is a really dirty way to solve the problem so I hope there are other possibilities.

Thanks again.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

Is it in principle possible to extract the text from any listbox or combobox?

Since any custom control can arbitrarily contain the word ListBox or ComboBox in its name, I would have to say "no".
An application can be designed to store its text privately and draw it on the screen only as needed. In such a case, there
would be no external/direct access to the text (other than something fairly difficult such as ReadProcessMemory).

I have also thought about using OCR technology to "read" the text off the screen

This may be the best approach in this case. Here is a nice command line OCR tool that daonlyfreez recently posted:
Optical Character Recognition (OCR) - gocr [CLI]