I'm trying to click a button on a windows application from other application. Basically, I want to click app B's button from app A's code.
I can use winapi findWindow to get a handler. The problem is that I have no idea the name of the button on the app B. Is this possible to list all the names or ids of an application?
I'm using c# to make it happen.
Since you're looking at suggestions (it's a pretty generic question really, it might or might not work depending on what other app/window is, is it e.g. browser or a 3rd party app etc., does it support automation)
Take a look at this closely related answer (it might be a duplicate but you're kind of 'looking for' still so maybe note).
Accessing Elements from Other Processes
Also this one on how to 'access' other app's 'inputs'
Pinvoke SetFocus to a particular control
I have not tested this. But it looks like a intressting libary. Maybe there is some function you can use. It is called White. This is just a sample:
Application application = Application.Launch("foo.exe");
Window window = application.GetWindow("bar", InitializeOption.NoCache);
Button button = window.Get<Button>("save");
button.Click();
You can use tool such as Spy++ (included in any Visual Studio except Express editions) to find name and class of that button and then use these information as parameters of FindWindow().
Related
So I'm sure there's an easy way to do this but I don't know the exact terminology for what I'm wanting.
Essentially in my C# xaml uwp app I have a couple objects that need to have details added to them, kind of like file properties. I have a button that I would like to open up another window (still part of the app), just to enter in the properties. I just don't know the terminology to look up what this window would be called or find documentation for it. So the exact same as when you're in a file browser and you open the properties of a file; it opens in a little extra window that you can drag around.
I don't want to be able to use the main window while the properties window is open, and of course they need to be able to transfer data between one another.
In my previous apps I've simply made a grid that appears over everything else in the middle of the app and shaded the outer area. A workaround as I didn't know how to do this.
Can anyone help me out?
Maybe you can use Dialog refer to https://learn.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/dialogs-and-flyouts/dialogs.
Dialog controls are modal UI overlays that provide contextual app information. They block interactions with the app window until being explicitly dismissed. They often request some kind of action from the user.
iI there any way to add a GUI component to an application which is already running?
I.E. Add an extra tab into a third party GUI?
I have a third party application where I need to add an extra tab into the tabbed interface (or even a button to link to a new form).
I can see the UI components in UISpy and Spy++ but Can't see a way to alter or add them...
Any ideas? Maybe altering the memory?
Update:
The application I have created to wrap around the third party app is .NET but the third party app is written in VB6
I suppose it's entirely possible with reflection, with the aid of Reflector, assuming it's not been obfuscated. Explore around the reflected source until you find the class of the form, and the instance of the form that you want to modify, then you can invoke the Controls.Add method, or anything else you need to, with reflection. But unless you know exactly what you're doing, you could run into some unexpected behavior from the application.
You can use ResHacker.
http://www.angusj.com/resourcehacker/
Basically, each GUI form is saved as a resource inside of a particular Windows executable. ResHacker has a built-in GUI editor for editing "Dialogs" (as they are referred to in ResHacker).
I assume it's a .NET WinForm app. If you do not have the source files and the app isn't too big, you can try 'decompiling' it and add in your code to become a new app.
I'm a great fan of Lutz Roeder's Reflector which generate code from the CLR codebase.
Here's a link to his tools. http://www.lutzroeder.com/dotnet/
Update:
darkassassin93 is right, hopefully the app is not obfuscated :)
You should have strong reason for doing that.
I think you can start with Add Tab using pure WinAPI and TabCtrl_InsertItem Macro
If you have HWND of TabControl you can try to add your own tab. with TabCtrl_InsertItem. Although i don't think it's possible to do that from another process. But you should try.
I would like to have a form that has 2 windows file explorer(explorer.exe) views.
I know I could code a file browser in a few days, but I much rather just use instances of explorer. I dont need to re-invent the wheel, just two windows connected by a form.
Is this possible in C#?
You can use this controller and then just too 2 of them in the same window
There is no means by which to "host" an explorer window, as you want to do. The only way to come close is to use an OpenFileDialog, but that is obviously unsuited to what you're going for. There is no API around the explorer window; no matter what approach you take, you're going to have to use an actual control. There are plenty available online, such as the one linked to by Baget, but nothing built into .NET.
You need to use embeddable controls like Shell MegaPack for this.
I would like to setup Feedback link on every windows form, so that user can send suggestion about design, functionality etc.. using C# (.NET 3.5) but I could not find solution.
Any help or suggestion will be appreciated.
On every form? You could create a "FeedbackLink" UserControl, and place that whereever you like. I wouldn't recommend trying to do it as a clever blanket-thing, because you can never assume the place you want the feedback hyperlink won't be used by something else.
My suggestion would actually be to add it to the "Help" menu on your main form, and possibly in some kind of (very intrusive) pop-up dialog. Maybe do it the way Visual Studio tackles it - by putting an icon in the systray with a bubble that pops up for the user to click on?
Example image (might take a second or two to appear):
Example http://www.freeimagehosting.net/uploads/b7939d58ae.png
I am looking for a decent replacement for the standard windows YES/NO or YES/NO/CANCEL MessageBox.
I have often seen these standard dialogs misused in ways such as: "To save in plain text answer YES, or to save in html answer NO". Obviously, the text should read "Save As: and the "buttons should be labeled "Text" and "HTML". It is not a yes/no question that is being asked, and although it could be phrased that way, it would not be easy to read and understand.
Microsoft gives no way to change the text on the buttons. There is no fast/simple way to build a replacement from scratch... as evidenced by the number of applications using the awkward style mentioned above.
Is there any free C# replacement dialog or MessageBox out there that lets you at least:
- specify the number of buttons
- specify the text to appear on each button
- specify the default button
I have looked and have been unable to find one.
(I would build one myself, but I am not familiar enough with all the behaviors that a fully functional control should have, since I only need/use/know a small subset. Two examples I don't use: themes and internationalization. I need something that my coworkers will also want to use.)
Check out Dissecting the MessageBox on CodeProject. The project is a bit dated, but it's pretty much exactly what you're looking for and it shouldn't take much to update it.
Depending on your target platform, a task dialog may be a good way of doing this. There is a .NET wrapper for task dialogs in the Windows API Code Pack. However these are provided only in Windows Vista and above, not in XP or 2003.
Frankly, it is not that difficult to create such a Messagebox yourself, we have such a thing working in the current app we are developing.
What you need is a FlowLayout for the buttons that will auto-align any buttons you create. Our API then has something like (params Tuple<string,DialogResult>[] buttons)
Tuple is a helper class that contains two values. The string is the Text of the button, the Dialogresult is the one our messagebox returns when the button with said text is clicked.
I agree with Frank. It wouldn't be too difficult to create your own generic form that handles this for you. Without getting into code, the form should do the following
1) Have a property to set the message you want to show to the user.
2) Have a method for adding buttons, with 2 arguments, one for the button text, and one for the dialog result
3) When the form is displayed, it should be in modal dialog mode so that the rest of the application is inactive while until one of the options is clicked.
So, to create a Save As/Don't Save/Cancel, you would add 3 buttons in step 2, all with the appropriate button text and dialog result.
Using Flow layout, you should be able to get it to display properly regardless of the size of the message, or the number of buttons.