Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to 'read' the selected text in the active window?

2 views
Skip to first unread message

Vladimir Stefanovic

unread,
Dec 3, 2004, 4:10:00 PM12/3/04
to
How (in general) to 'read' the selected text in the active
window from a completely unknown app?

I saw apps (dictionaries) that uses global keyboard hook
to to copy to clipboard the selected text.

That means I just select some phrase in MS Word (not
needed to copy it to clipboard), then press some special
key which actually makes copying, and finally processing...


Best regards,
Vladimir Stefanovic

Remy Lebeau (TeamB)

unread,
Dec 3, 2004, 4:26:50 PM12/3/04
to

"Vladimir Stefanovic" <sp...@not.needed> wrote in message
news:41b0...@newsgroups.borland.com...

> How (in general) to 'read' the selected text in the active
> window from a completely unknown app?

That is not a trivial task. Finding the active window, and the active child
control inside of it, is very easy - GetForegroundWindow() and
GetActiveWindow(). Determining the proper way to query the text from the
active child, on the other way, is not so easy. Different controls have
different ways to represent selected text, and thus different ways to copy
that text.

For a ListBox control, for example, you have to use the LB_GETCURSEL and
LB_GETTEXT messages.

For an Edit control, on the other hand, you have several options:
1) EM_EXGETSEL and EM_GETTEXTRANGE
2) EX_GETSELTEXT
3) WM_COPY.

For third-party custom controls, it could be something completely different.

> I saw apps (dictionaries) that uses global keyboard hook
> to to copy to clipboard the selected text.

A global hook requires the user to press a certain key combo to invoke the
copy, but the copying itself still involves identifying what type of window
contains the text to copy, and then deciding how best to copy that text from
it.

> That means I just select some phrase in MS Word (not
> needed to copy it to clipboard), then press some special
> key which actually makes copying, and finally processing...

See above.


Gambit


0 new messages