Peyman Javanbakht
Peyman Javanbakht

Reputation: 21

Code for copying the text from another window

Is it possible to write a code that will copy text values from a window belonging to another application?

I have an application that gives me live results(only texts), every 5 minutes, and I cannot copy paste them every 5 min.

Screenshot

Upvotes: 1

Views: 810

Answers (1)

Dai
Dai

Reputation: 155608

Maybe.

It depends on how the target application is exposing its text to the OS.

If the application is using a private 2D/drawing library to render text by itself to an in-memory or in-VRAM buffer, then no. You'll need to grab a screenshot and perform OCR on it - or you could inject your own code into the target process and intercept those 2D/drawing library calls to get the text being rendered.

If the application is using the Windows-provided GDI then there are ways of intercepting those calls to get the text. I believe Direct2D and DirectWrite also offer straightforward ways of intercepting/profiling their calls as well.

If the application is using a GUI framework or platform like WinForms or WPF then there are ways of inspecting the rendered view's object-model to extract data and text - this is how various "Spy" utilities work. "Spy++" (spyxx.exe included in Visual Studio and the Windows SDK) can inspect native Win32 hWnd windows and "Snoop" is a very powerful tool for inspecting WPF applications (Visual Studio's built-in Visual Inspector does the same thing).

Additionally, often GUI frameworks and platforms will support the OS' built-in Accessibility platform and will expose on-screen data as machine-readable structured data for use by screen-readers for the blind and visually impaired as well as automation software. Windows' built-in platform is called Active Accessibility and Windows UI Automation. There are premade tools you can download to inspect Active Accessibility data.

If it's a HTML application (e.g. Windows HTA, Electron app, Chrome desktop app, etc) then that's another topic.

Upvotes: 3

Related Questions