• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

How to get text from other windows

Hi

i have a difficult one...
i'm trying to get the selected text from any window (not my form)
i tried WM_GETTEXT and all the others in the SendMessage group, but it works only on specific text boxs... (not working on microsoft office for example)

i also tried to use the MSAA (Microsoft Active Accessibility) to get the text, but this one also brings the text only from some windows..(also not working on microsoft office)

the only thing that is working for me is to use the clipboard (emulate CTRL+C at the active window), which works fine, unless you are working with the microsoft office (or any other multi-clipboard program) and then the user sees all the copying that i do...

i know it can be done, babylon dictionary takes the clicked text from any window, if anyone knows how they might do that please let me know..
if anyone knows how to do it without knowing how babylon does it, please let me know too :)

thanks in advance,
Yaniv
0
kalsky
Asked:
kalsky
  • 5
  • 5
  • 3
4 Solutions
 
Bob LambersonSoftware EngineerCommented:
Check out this previous question of mine on EE. The problem was similar and it may give you some insight.  Q_21052994.html  I also have discovered a neat program called Capture Wiz that may help you. It can be found at http://www.PixelMetrics.com
0
 
Bob LambersonSoftware EngineerCommented:
0
 
Julian HansenCommented:
WM_GETTEXT won't always work - for instance a rich edit control you have to use a completely different procedure.

Refer

http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21355647.html
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kalskyAuthor Commented:
BobLamberson, i looked at the posted code, but it's very specific code (only for vb form and labes) and i want something global, i can get the text from the office windows if i want to be specific, but i'm trying to find something that will suite for all the programs/windows

julianH, what you gave me is also specific for one type of text box, i'm trying to avoid handling all the possible text boxs in a different code...

maybe the Babylon use some kind of OCR, and if they do, they do it very good, finding any selected word in any weird font that i tried in the MS Word...

BTW: i'm using VB but i will understand any other code too (i think) if it's using APIs...


0
 
Bob LambersonSoftware EngineerCommented:
The basis for much of the API discussed is that all windows have handles, and it has nothing to do with office. The code I was referring to is specific to labels, because labels are not windows and do not have a handle. The code uses the window handles to get to the "window" that is a container for the label by using windows handles.
Thus the same approach will work with any windows based program that has windows because the windows will have handles.
If you study how the API works, you will see that you can use certain functions to find container windows by name and/orclass and return the handle, which will allow you to enumerate all or most of the controls or windows that have that parent.

If you read my posting you will see how the Function EnumWindows and Function EnumChildWindows, along with the functions GetWindowText and some of the other API functions can be used to do what you are after.

Bob
0
 
kalskyAuthor Commented:
Bob, i apritiate your quick responses..
what i'm trying to say, and correct me again if i'm wrong, is that using the code you gave me, i will have to make a specific routine for the microsoft word, and a specific routine for notepad, etc..

let me try another question, are you sure that these APIs will bring me back that text from the Word ?
i know that the window that has the text there is of class "_WwF", but it's not responding to WM_GETTEXT...

i have to search in each window the child that i need and then gettext from it ?

i can't find any reference on the internet that the office responeds to API calls...


0
 
Julian HansenCommented:
kalsky,

The problem you have posed has no simple answer. With windows programming the developer can choose to use the default draw method for a control or choose to subclass the control and draw the control content with custom code. Alternatively, developers can develop their own controls that render text and content in a custom form.

How information is retrieved from the control is dependent on the facilities provided by the developer of the control. The article I posted was by way of an example of why there is no silver bullet for this one - each control type potentially has a different mechanism for accessing the content.

OCR - sure you can use this but this is good only for what is displayed on the screen. If you have a Word or Notepad document where the text scrolls off the visible screen area - OCR will help you only with what is displayed on the screen - you would have to implement some auto scrolling functionality to use OCR to pick up all the content.

WM_GETTEXT is limited because of the variance in the quantity of data it can return. For this reason its use is limited to retrieving text where the text is "of reasonable length" i.e. a Window Title or the contents of a text box or other such simple controls. When you are dealing with Notepad with potentially megabytes of text or a Word document (that has embedded objects in addition to text) WM_GETTEXT is no longer a feasible option - again refer to my earlier post on retrieving info from an Edit control in notepad.

Basically it comes down to how the control was implemented. Windows is a message based environment - developers can choose which messages their code wants to respond to and if they don't implement a handler for WM_GETTEXT then there is nothing you can really do about it.
0
 
kalskyAuthor Commented:
thanks julianH

actually, i need only the visible text on the screen, so OCR may help me...

if anyone knows how can i do ocr...

thanks

Yaniv
0
 
Julian HansenCommented:
Yaniv,

Are you looking for source code, freeware software or would you consider a commercial product?

Julian
0
 
kalskyAuthor Commented:
i prefer source code so i could integrate it in mine instead of making the user install another program...
0
 
Julian HansenCommented:
Not really my field but a quick search on Google revealed the following

http://www.simpleocr.com/ (Quite pricy)
http://www.codeproject.com/dotnet/simple_ocr.asp

Julian
0
 
kalskyAuthor Commented:
thanks Julian and Bob, i'll look further..
0
 
Julian HansenCommented:
you are welcome - thanks for the points
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now