How to get the current Mouse Pos's text???

I want to get the current Mouse Position
's text.
How can I do it??

I also hear of that it's some difference
bettween IE's Text grab and Normal text grab.

Can someone give me a sample??
:)

Thanks!!!
God bless you
:P
keronAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kretzschmarCommented:
? what exactly does you mean ?
- the caretpos in the text
- the caretpos in sreen-coords
- the letter under the mousecursor
- the mousecursorpos relativ to textcontrol
LischkeCommented:
Keron, what you wanna do is extremly difficult. It requires some very low level programming steps. I have done this last September for our on-click dictionary and had a real hard time. If you only need the text from an edit control then it is somewhat easier but for labels and other static text (button captions etc.) you have to go the hard way...

Ciao, Mike
keronAuthor Commented:
:)
I means
- the letter under the mousecursor
when the mouse on a text,you can get it!

the text maybe in other runningprogram;
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

keronAuthor Commented:
yeah

Lischke

something like on-click dictionary

You had done it?
can you give a sample???

thanks a lot!
LischkeCommented:
One cannot give a sample for this as it involves about 3000 lines of code which depends heavily on each other. But I can give you the raw direction.

- install a global mouse hook
- on activation it is mapped into the process for which the mouse message is meant and you can redirect all text out function (WinNT) or directly hook the GDI (16 bit only, Win9x only )
- you need to make the particular window to draw its text again and wait until the text is through your hooks (e.g. using RedrawWindow(..))
- after this you need to setup the results and send it to your application (memory mapped files or pipes)

Further information:
- Detours library: http://research.microsoft.com/sn/detours (WinNT only)
- SetDDIHook (MSDN) (for Win9x only)


Ciao, Mike
philipleighsCommented:
Or an easier way:

Add a TTimer to a form.
In OnTimer event call GetCursorPos.
Now call WindowFromPoint.

That will give you a window handle.

Now send a WM_GETTEXT message.

I guess that would work for edit boxes and the like under the cursor, but for the view area in IE you'll need some other approach.

Cheers,
Phil.
MadshiCommented:
I'm using Babylon Translator on my machine and it doesn't use Mike's approach, but instead it makes a snapshot of the area under the cursor and then does something like OCR on that bitmap.

Regards, Madshi.
keronAuthor Commented:
Oh
That's a interesting way
means that it can also get the text
on image,Cool!
But OCR's realize is ......hard....
 :P
keronAuthor Commented:
Oh
That's a interesting way
means that it can also get the text
on image,Cool!
But OCR's realize is ......hard....
 :P
LischkeCommented:
Phil, your suggestion is obviously only working for text of windows and in case they have a caption only this one is returned. Try it e.g. with notepad's text. This does not work.

Madshi, are you really sure they use OCR? How do you came to this conclusion? To do a quick test write a little program with one form on which one label is placed. Set the label's caption to some arbitrary text and then set its font height to -3. Then run the program and try Babylon again. Does it still recognize the text (I assume it does with normal sized text)? If yes then forget about OCR.

To be honest, I don't believe at all that they use OCR as there can be too many different font styles and sizes. It would simply be to unreliable.


Ciao, Mike
MadshiCommented:
Mike, it works even on bitmaps. I've just now tried it on the "Experts wanted - are you ready" bitmap in the top left corner of this html page (and Babylon found "ready"). You're right, it's a bit unreliable, sometimes Babylon gets some characters wrong. But it works unbelievable well!

www.babylon.com

Regards, Madshi.
LischkeCommented:
Working on bitmaps is no criterion. The solution I wrote works even if you draw text on a bitmap and blit this bitmap on another bitmap and rotate this bitmap and put it on the screen. No OCR, believe me :-)

Ciao, Mike
LischkeCommented:
Madshi I have to correct myself. It MIGHT be OCR (still not sure) but is definitely also not a similar technique I use. I downloaded the demo and (despite that it crashed after a few recognizion tasks) it was very unreliable. Simply setting a label font style to italic prevented Babylon from successfull recognition.

Ciao, Mike
MadshiCommented:
If it works on a jpg (or gif) bitmap that was downloaded from the internet, it CANNOT be anything else, but only OCR.

Well, I had almost no crashes yet, but yes, italic is a problem for Babylon...   :-(
intheCommented:
if Babylon5 crashes some people are in trouble  hehehe...
scirocco1Commented:
May be this little code can help you.
Use this code on a form.

// Code for Distance between two points.
funcTion Distancia(Pt1 : TPoint; Pt2 : TPoint) : Double;
var
  dx : LongInt;
  dy : LongInt;
begin
  dx:= pt1.x - pt2.x;
  dy:= pt1.y - pt2.y;
  Result := Sqrt((Dx * Dx) + (Dy * Dy));
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift:TShiftState; X,  Y: Integer);
var
  Pt1 : TPoint;
  Pt2 : TPoint;
  Dist : Double;
begin
  Pt1.x :=  Form1.Width div 2;
  Pt1.y  :=  Form1.Height div 2;
  Pt2.x := x;
  Pt2.y := y;
  Dist := Distancia(Pt1, Pt2);
  Form1.Caption := IntToStr(Pt2.x - Pt1.x)+#32+IntToStr(Pt1.y - Pt2.y)+' = '+
                   FloatToStr(Dist);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  Form1.Canvas.MoveTo(Form1.Width div 2,0);
  Form1.Canvas.LineTo(Form1.Width div 2,Form1.Height);
  Form1.Canvas.MoveTo(0,Form1.Height div 2);
  Form1.Canvas.LineTo(Form1.Width,Form1.Height div 2);
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Invalidate;
end;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.