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

How to capture the word displayed on screen?

I want my application can capture the word displayed on the screen.

I know if the word is in picture, i could not capture it.

But if it is displayed through fonts files, how can i capture it after the mouse pointer stay on it a second?
0
yc
Asked:
yc
  • 6
  • 3
  • 2
1 Solution
 
MotazCommented:
That is a deffecult task..

Motaz
0
 
MotazCommented:
That is a deffecult task..

Motaz
0
 
ycAuthor Commented:
Hi, Motaz

Just as you said! I think the question is very difficult.

I will add the point for it every day! :)

I think i can do some translating between two language through the function.


Regards

Ye Chen
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
MotazCommented:
What did you want to do exactly yc ?

Why did you want to capture text in a bitmap ??

Motaz
0
 
ycAuthor Commented:
Hi, Motaz

I do not want to capture the words in a image.

I only want to capture the word print to screen.

The following is my thinking:

1.) Modify the displaying function in API such as TextOut...
When the mouse position is in the area of which the word's position printing to screen, transmit the word to my application.

1.) Set a timer:
It will active a second or less than a second.
when it works, it can recording the mouse postion and compare with the last time. If the position is same than do 2.)

2.) Force to refresh the displaying the mouse position. The result is 0.) will capture the word on mouse position.

How do you think?

Regards

Ye Chen




0
 
ycAuthor Commented:
Hi, Motaz

I do not want to capture the words in a image.

I only want to capture the word print to screen.

The following is my thinking:

1.) Modify the displaying function in API such as TextOut...
When the mouse position is in the area of which the word's position printing to screen, transmit the word to my application.

1.) Set a timer:
It will active a second or less than a second.
when it works, it can recording the mouse postion and compare with the last time. If the position is same than do 2.)

2.) Force to refresh the displaying the mouse position. The result is 0.) will capture the word on mouse position.

How do you think?

Regards

Ye Chen




0
 
belgianbasmanCommented:
Hello Ye Chen,

I think that, once you output a string to a canvas with textout, it becomes part of a picture, and you can't retrieve it any longer.  There is a solution to your problem, though....

What you could do is store all strings you output to the canvas with an array, a linked list of records or a database.  Then in the onMouseOver event of the component that is the owner of the canvas, do ...

suppose for argument's sake that you opt for a linked list of records. In the TYPE-section of your .pas file enter ...

DrawnTextPointer = ^DrawnText;
DrawnText  = Record;
   top : Integer;
   left : Integer;
   text : String;
   Next : DrawnTextPointer
END;

in the VAR-section enter :

CurrentDrawnText, FirstDrawnText : DrawnTextPointer;

Now, in an initializing section, set FirstDrawnText to nil.
Then, whenever a text is drawn to the canvas do this ...

CurrentDrawnText:=new(DrawnText);
if FirstDrawnText=nil then
  begin
      FirstDrawnText:=CurrentDrawnText
  end
else
  begin
      CurrentDrawnText^.Next:=FirstDrawnText;
      FirstDrawnText:=CurrentDrawnText;
  end;
CurrentDrawnText^.Next:=nil;
CurrentDrawnText^.Top:=  <top value of the point where the string has to be drawn>
CurrentDrawnText^.Left:=  <left value of the point where the string has to be drawn>
CurrentDrawnText^.Text:=  <the string that has to be drawn>
.. <draw the string to the canvas the way you are used to, with TextOut>

then in the OnMouseOver enter :

currentDrawnText:=FirstDrawnText;
while not CurrentDrawnText=nil do
   begin
          if ((X>CurrentDrawnText^.Left) AND (X<(CurrentDrawnText.Left + Canvas.TextWidth(CurrentDrawnText^.Text))) AND (Y>CurrentDrawnText^.Top) AND (Y<CurrentDrawnText^.Top + Canvas.TextHeight('A'))) then
     begin
               do whatever you need to do when the mouse goes over a text
               break;  {will jump out of the loop for efficiency}
     end;
     CurrentDrawnText:=CurrentDrawnText^.Next;
   end;

This is what happens:  for every record, you will check the following condition :
"Is the current X position of the mouse greater than the left value of this text, and smaller that the left value of this text plus its width, and is the current Y position of the mouse greater than the top value of this text, and smaller than the top value of this text plus its height?"  This means "Is the mouse currently over the text in this record?"
if the answer is yes, the if-statement returns TRUE, and then you can do whatever it is you want to do in such a case.

I hope this works, I typed it from memory.  

Good luck !!

Basman
0
 
ycAuthor Commented:
Hi, belgianbasman

Thanks your helping.

But how can replace the API's text output function.
Now i known TEXTOUT is function need to replace, i wand to know
if there is other function need to modify?

Regards
Ye Chen
0
 
belgianbasmanCommented:
You don't have to replace TextOut, just do some other stuff around the calling of TextOut, like the record keeping.

I'll paste in a fragment of the code from my proposed answer, and indicate the line you have to replace with a textout with ##**

CurrentDrawnText:=new(DrawnText);
if FirstDrawnText=nil then
  begin
      FirstDrawnText:=CurrentDrawnText
  end
else
  begin
      CurrentDrawnText^.Next:=FirstDrawnText;
      FirstDrawnText:=CurrentDrawnText;
  end;
CurrentDrawnText^.Next:=nil;
CurrentDrawnText^.Top:=  <top value of the point where the string has to be drawn>
CurrentDrawnText^.Left:=  <left value of the point where the string has to be drawn>
CurrentDrawnText^.Text:=  <the string that has to be drawn>
##** .. <draw the string to the canvas the way you are used to, with TextOut>  ##**

That should do the trick.

0
 
ycAuthor Commented:
Hi, belgianbasman

Does your code can capture the text printing to screen by other application?

I want capture the word not only print by my program, but also by the other application and the 95/98/nt system.

Regards

Ye Chen
0
 
ycAuthor Commented:
Adjusted points to 55
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

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