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.
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.
Related
I have an extension on a WPF program, and I need to simulate a series of keypresses for it. WinForms is unable to be used as a reference. I cannot show code, but none of my code has to do with this anyways. I just need to simulate a keypress at the most basic level so the program thinks the user is typing. Also, the use of external libraries cannot be used because the extension is a single .DLL file added to hundreds of systems, so whole libraries cannot come with it. Thanks - Ethan
You can accomplish this through the use of a technique called Platform Invoke (P/Invoke for short). This lets higher-level code interact with the lower levels of code used by the platform it's running on.
The "higher-level code" in this case is your C# code, the "platform" is the Windows OS and the "lower-level code" are the native libraries that are part of the OS. These native libraries include code to do such things as send keyboard and mouse input, and since these libraries are part of Windows itself, you don't have to package them with your program.
The method you will want to p/invoke is called SendInput. It's used to send keyboard and mouse messages to the active program, just as if they were sent by a physical keyboard or mouse. Take a look at this page on pinvoke.net for instructions and an example on how to implement that method. That site is a good general resource for all your p/invoke needs.
I want to automate simple Windows Application using MSAA. I am not getting Idea that how to find the control (say TextBox and Button) and to get value of them(say get value of TextBox and click in case of button).
Why do you want to automate using MSAA? Microsoft's current way is UI Automation.
From Wikipedia (emphasis mine):
UIA is similar to Microsoft Active Accessibility (MSAA) in that it
provides a means for exposing and collecting information about user
interface elements and controls to support user interface
accessibility and software test automation. However, UIA is a newer
technology that provides a much richer object model than MSAA...
With UI Automation you can automate by creating a native or .NET application or use a 3rd party tool like RIATest that relies on UI Automation.
(Disclamer: I am affiliated with RIATest).
The following assumes you'll be developing your automation program in C/C++, as I'm not sure it would be easy to use MSAA from .NET (it might be possible though!)
If you don't want to use C++, you might investigate using MS UI Automation from .NET.
To get started developing an automation client app using MSAA and C++, I suggest:
Install the Windows SDK for Windows 7 and .NET Framework 4
That will install the Inspect.exe tool - find it under:
Programs > Microsoft Windows SDK v7.1 > Tools > Inspect Objects
Launch Inspect.exe and switch the upper left dropdown menu from "UI Automation" to "MSAA"
Launch your application under test and mouse over its UI elements - the MSAA properties of the elements should display in Inspect.exe
Write your automation code :)
An important choice will be to decide whether to use event-driven techniques to locate your elements, or simply start at the top level (the desktop), find your app among the child elements of the desktop, and drill down into your app's element tree from there.
There's a good event-driven MSAA tutorial on codeproject.com at: http://www.codeproject.com/Articles/18290/Introduction-to-Microsoft-Active-Accessibility
Tutorials on tree-based navigation in MSAA seem a little more scarce. I would start with the MS docs - I recommend the first one:
Active Accessibility Client Interfaces and Functions
Active Accessibility User Interface Services
Active Accessibility Start Page
My app needs floating palette windows. I've already implemented this behavior on my own and it worked great for when it was a single document app, but now my app requires multiple document windows. My attempts to adapt the palette windowing system for this now makes the implementation too hacky and doesn't work very well when switching documents.
Windows has an extended window style, WS_EX_PALETTEWINDOW, which I have tried using through overriding CreateParams but this keeps my floating windows on top of EVERY other running app. I need them to just stay on top of my app and go away when another app is enters the foreground.
Any suggestions?
Edit: Preferrably solutions should not involve the use of MDI containers as I need document windows to be top level windows in their own right.
Use DockPanel suite. It is a ready made library for handling tool windows.
In addition you can enable user customizable docking of the tool windows if you like.
I use UI Spy and Spy++ to view windows text of some windows, but none offers a result. As people said, some windows are built up and executed by some components, say they are embedded inside those components. Except the two tools to view the window handles, text, could you introduce me other tools or ways to get a window text or handle without using hooks ?
Edit: I also use Spy Object to retrieve windows objects information and search from ancestors till I can meet the right object but this tool to the particular windows I am watching is incapable to do the job because it also reports incorrect parents positions in ancestor hierarchy, I try out the MAAS and UI-Automation without luck, Thank you for you help.
Edit3: I don't like their windows'ideas of internal designs (I mean only they-designers- know how to untie the knots)
Usually the Accessibility APIs are used, the ones used for text-to-speech screen readers for blind users. In your question you mentioned MAAS, did you mean MSAA (Microsoft Active Accessibility)? If not, that's where I'd look next.
http://white.codeplex.com/ is a great framework which does such things.
White is a framework for automating rich client applications based on Win32, WinForms, WPF, Silverlight and SWT (Java) platforms. It is .NET based and does not require the use of any proprietary scripting languages. Tests/automation programs using White can be written with whatever .NET language, IDE and tools you are already using. White provides a consistent object-oriented API, hiding the complexity of Microsoft's UIAutomation library (on which White is based) and windows messages. Only stable versions of White are released, so all releases are production-ready.
Using ExternalInterface in AS3 is it possible to call OS (C#?) functions within XP?
Example: Set the desktop background to a image supplied by a flash app?
If it is possible would it be different calls when applied to different OS. And what about cross over the Mac?
Any information would be great
Thanks
If you're launching the swf from within a C# app, external interface will do just fine. Nothing will change on the flash side, but you'll need to go through a couple hoops to get it to work in C#. It's not as simple as AMF or External Interface to JS.
All the communications to C# get converted to XML describing the data, and you've gotta write XML to send back to flash. Other than that though, its relativly simple.
Here's some info on how to do it. The AS portion is Flash 8/AS2, but the C# portion should say the same.
When working with Flash from a webpage or as a desktop app, you are limited to a small security sandbox and you will not be able to make any relevant OS call. I thought that switching to AIR would give the developper more flexibility but it doesn't seem correct either. From "The Pros and Cons of Adobe Air":
AIR apps have
file access, clipboard access, support
multiple windows, support drag and
drop, and can trigger notifications
(toast in Windows). If you app needs
to interact with the desktop in other
ways, the chances are that AIR is not
suitable. For example, there is no
access to COM automation, and no way
to execute external applications. The
reason is to maintain cross-platform
compatibility. That's a worthy goal,
but it would be good to have a way out
of the sandbox. Unlike Java or .NET,
you cannot extend AIR with custom
native code libraries. Nor can you
call operating system APIs.
As Alex Jillard commented, if your swf is called inside a C# desktop application, you should be able to access more OS funcionalities although I'm not sure how.
You could use as already mentioned AIR. Another idea would be to use HippoHX (I haven't written this, the similarity with my username is just coincidence). It runs on top of the NekoVM and gives you unrestricted (so no limitations like in AIR ) access to the system.