Solved

get text(word) at mouse cursor from any program

Posted on 2003-11-04
8
385 Views
Last Modified: 2010-04-05
Question: how to get text (just simple word) where the mouse cursor is, if it is possible?

For example the user moves mouse cursor anywhere in any windows application, presses some keys combination (shift+ctrl+a or other), then my application must get text at the mouse cursor. I need this to do a translation of that text or word, and possible to show a hint for that text o displaying translated message in some window on top.

I know that there is such possibility. But I don't know where to start from. If it is too complicated  plesase give some ideas where to start from. Thanks.

Marko
0
Comment
Question by:MarkoB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

by:raidos
ID: 9678848
only method i can think of is some form of OCR reader of the screen...
and that isn't very simple to do...

never done it, don't know how to do it either...but theoretically it could work.

Regards
//raidos
0
 

Author Comment

by:MarkoB
ID: 9678980
If it is so difficult, maybe to limit the task, is to get the text from Microsoft native applications, in text editing (viewing) control: Word, Internet Explorer, WordPad.
It should be a way to get text at mouse cursor, I think.

I've seen such implementation in MacMillian English dictionary.
0
 
LVL 1

Accepted Solution

by:
rvicentiu earned 250 total points
ID: 9679695
there are a few ways to do it,  here's the easy way :)
this should work for anything (except some listboxes without LBS_HASSTRINGS defined)
to test this make sure the mouse is where it should be before calling the function

var text: PChar;
    hWnd: dword;
    point: tpoint;
begin
  text:=stralloc(1000);
  GetCursorPos(point);
  hwnd:=WindowFromPoint(point);
  SendMessage(hwnd, WM_GETTEXT, 1000, DWORD(@text[0]));
  if length(text)=0 then begin
    Windows.ScreenToClient(hwnd, point);
    SendMessage(hwnd, LB_GETTEXT, SendMessage(hwnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(point.X, point.Y)), DWORD(@text[0]));
  end;
  strdispose(text);
end;
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!

 
LVL 1

Expert Comment

by:rvicentiu
ID: 9679761
oh, in case you haven't figured this out yet the maximum length of the text in my example is 1000
use WM_GETTEXTLENGTH and LB_GETTEXTLEN to get the length of the text and allocate the buffer before getting the text
in a rich edit control, if the text to be copied exceeds 64K, use either the message EM_STREAMOUT or EM_GETSELTEXT
see Win32 help for more info
0
 

Author Comment

by:MarkoB
ID: 9684756
Thanks rvicentiu,
I'll try this code soon. And what is that another not easy way? :)


0
 
LVL 1

Expert Comment

by:rvicentiu
ID: 9689662
you can install a WH_GETMESSAGE hook with SetWindowsHookEx and intercept for example the WM_MOUSEMOVE message to get the text from the window it was being sent to
0
 

Author Comment

by:MarkoB
ID: 9694398
ok. I managed to get text, but sometimes it gets too large to analyse big amounts of text, For 99% of cases I just need a single word (at mouse cursor),
the easier task would be to get just a selected text,
the only message I know is EM_GETSELTEXT, but that works fine for RichEdit,
but
how to get selected text from Internet Explorer, Outlook, or Word?
I mean without asking users to copy that to clipboard.
0
 

Author Comment

by:MarkoB
ID: 9731210
It looks that it is not possible without some OCR code. So I acceppt the answer fot the rivcentiu answer. Although I didn't managed to do, what I intended to do - to get a word at mouse cursor.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 88
Unique identifier on a terminal server (rdp) 4 85
Adoquery sql  left join does not work 25 120
Automatic field translation delphi 10.2 6 45
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question