Home All Groups Group Topic Archive Search About

Text From Another (Application) Window...

Author
21 Dec 2006 5:04 PM
Jason Richmeier
I think this issue has been posted at a number of locations on the internet
but I have yet to find a satisfactory answer.

I would like to be able to grab the (selected) text of another application
window to use for processing.  For example, if I type "ABC" into another
window (be it Notepad, Word, or some other application, highlight this text,
and then fire my application up, I would like to be able to get the text
"ABC" from the other window within my application.  I figure this will
involve numerous calls to the Win32 API, but I am not sure what functions to
call.

Any help will be greatly appreciated.

Thank you,

Jason Richmeier

Author
22 Dec 2006 5:13 PM
Peter Ritchie [C# MVP]
You can use the GetWindowText function (or {Post|Send}Message with
WM_GETTEXT).  But, that won't work with Vista's new security schemes.  By
default an application won't accept messages (GetWindowText just uses the
WM_GETTEXT message) from applications or classes of applications it doesn't
explicitly give permission to.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


Show quoteHide quote
"Jason Richmeier" wrote:

> I think this issue has been posted at a number of locations on the internet
> but I have yet to find a satisfactory answer.
>
> I would like to be able to grab the (selected) text of another application
> window to use for processing.  For example, if I type "ABC" into another
> window (be it Notepad, Word, or some other application, highlight this text,
> and then fire my application up, I would like to be able to get the text
> "ABC" from the other window within my application.  I figure this will
> involve numerous calls to the Win32 API, but I am not sure what functions to
> call.
>
> Any help will be greatly appreciated.
>
> Thank you,
>
> Jason Richmeier

Bookmark and Share