control dialogbox of an external application - c#

I'm writing a program in C# to automate another application. I use user32 api. When the external application needs user input, my C# program fills the boxes and presses the buttons. When a new window comes up, I can find it and it's controls using findwindow() and findwindowex() function but when this dialog comes up (in the picture) I cannot find the controls in it(the buttons). Even UI Spy cannot show them. I tried to send key events to this window but nothing happened. Can you give me some tips how to go on?

Related

Accessing a WPF or WinForm Element From a Different Appdomain

I want to create an application that will run in the background and track the click actions of the mouse, and when the user clicks on an external WPF or Winforms app, the background app should be able to detect the clicked control and display its ID/name/text.
I'm not sure if this is possible, but since there are automation tools that can perform similar actions, I think it should be possible. For example, with some tools it is possible to get the "window" object using the external app's PID, and then the controls (for example a button) can be accessed by providing the ID of the control. However in my case it is the other way around. I need to get ID/name/text of the control the user has clicked.
I can obtain the mouse position using windows Hook
I can obtain the hwnd and Process ID of the window the user has clicked
So is it possible to obtain the information about the element clicked? Any help and advice is appreciated, thanks in advance.

How to find button handle in a WPF application, and click it programatically?

I'm trying to programmaticly (from my own application) press a button that is located on another running windows (WPF) application.
Todo so, a handle to the button would be needed. There are plenty of posts about how to get such a handle.
However, it seem that WPF applications don't present handles for their graphical components:
https://www.experts-exchange.com/questions/25665615/Spy-or-Windows-Api-Functions-not-locating-controls-on-child-window.html
Any clues on how to achieve an automated press on a button in such an application?
I don't have control of the source code for the application with the button.
I believe you'll need to look into UI Automation https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-overview

How to paste text into a different application with C#

Here is my scenario:
A user has two applications open. Let's say one application is Notepad with some text in it and the other one is my C# application.
A user now positions the mouse cursor somewhere inside the Notepad text and then clicks a button in my C# application. As a result, a text string from my application gets pasted in Notepad where the cursor was positioned.
My question is: what would a general approach be to accomplish the above, and possibly what classes etc. are recommended?
I would look into using interop calls to accomplish this. Look at specifically GetWindow() and SendMessage with the WM commands (http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx#system_defined) and GetDesktop().
GetDesktop will allow you to obtain all of the top level child windows of the desktop (all top level windows are children of the Desktop window).
You should then be able to use GetWindow to obtain the window handle you are looking for and then SendMessage to set the text into the textbox.

Most efficient way to get the handle of an Open window given its parent?

I'm working on a program to simultaneously control a handful of other programs of the same type.
So far I use EnumWindows() and collect the handles of the appropriate windows(programs) that I'm going to be controlling. Upon recognizing some keyboard keystroke, I iterate through all of the programs(there could be any number of them open) and I post click messages to all of these programs simultaneously by using EnumChildWindows() to find the appropriate windows(buttons) based on which keystroke was pressed and then using PostMessage() to actually send the click.
Each of these programs that I'm controlling has a button named "Load Settings" which opens an Open file dialog when clicked. What I would like to do is first use PostMessage() to click "Load Settings"(I have successfully gotten this far, what follows is what I'm trying to do). Then I want to get the handle of that Open file dialog window, fill in the text field with the path to the appropriate settings file that I've already determined, then click the "Open" button to finish the task and close the Open window.
My main problem is finding that Open window. Now, I can use EnumWindows once again to find that window but the problem with this is upon clicking "Load Settings" the Open window doesn't open instantaneously. I could sleep after clicking the button, then enum through the windows to find it, but that's not practical as the window could take any amount of time to open.
I've used spy++ to gather some information about this window, but as far as I know, none of it helps enough. Anyways, here is what I have found:
The window "Open" is the Previous Window to the program which it was opened from.
The window "Open"'s parent is the program which it was opened from.
The window "Open"'s owner is the program which it was opened from.
But even though it's listed as a child of the main program under its window properties, it's listed on the same level as the main program (it's not nested like other child windows).
I've tried FindWindowEx() and EnumChildWindows() but neither could find the Open window.
I would think there should be some way to, based on some handle, get the handle of the previous window.
Once that's working, then I need to fill the Edit(text field) window with the appropriate file path.
UIA is what you want, if your goal is to automate UI actions (e.g. for testing). UIA exposes the entire UIA tree which contains all applications active on the machine.
So what you'll see is a root node which has one child node for each application. Each of those nodes should represent the top level window of that application. Any further children depend on the application itself.
See more info at UIA Overview

How to know which control window got focus right now in Modal dialog using Win32 API?

I am trying to do something with the Modal dialog in Win7. To do that I need to know which control window has got focus right now by using Win32 API. If I could know which control is now got focus then I can send message to this window to do some specific task.
Could any one suggest me how should I know which control has got focus right now using win 32?
If you want to know which window has keyboard focus and you're only interested in windows belonging to your own thread use GetFocus.
Finding out which window in the entire system has focus requires a few steps:
GetForegroundWindow
GetWindowThreadProcessId
GetGUIThreadInfo

Categories

Resources