Adding GUI components to a precompiled application - c#

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.

Related

Is it possible to read data from Pane control type?

I've started using FlaUI for Automating my thick client .net application. The application is Windows Form based. The start was good and Login Form was identified and I could Login, but after that came the dead end and I found that almost everything in the application is developed as Pane control type.
So, there is grid, table etc. but they all just appear as Pane type when I see the object hierarchy using Inspect.exe or FLAUInspect tools. And nothing really appears in thier property, so it seems that nothing could be read. But before giving up I just wanted to check with experienced audience on this forum if there is really any way to get the data from Pane objects.
Please suggest if there is any way, even that means using other libraries like UIAutomation, TestStack.White, etc.
UPDATE: I now understand little more about this. So, the objects that are there in the pane are developed in syncfusion and devexpress. Is it possible to identify objects developed in syncfusion and devexpress using FlaUI or UIAutomation or TestStack.White, etc ?
I don't know if you have already tried the following steps. Have you add automationId's to your objects in xaml code with:
AutomationProperties.AutomationId="AnyID"
In the testcode, first initialize the main window of the application.
MainWindow = fApplication.GetMainWindow(fAutomation, null)?.AsWindow()
After that you can find your objects by the automationId's, like:
MainWindow .FindFirstDescendant(cf => cf.ByAutomationId(AnyID))
I did it this way, and don't have to know the hierarchy of my application. Maybe this will work?
Most UI Frameworks nowadays fully support UI Automation. So first make sure that you have a recent version of your framework (syncfusion, devexpress). In addition, some frameworks provide settings to enable UI Automation. Like for devexpress, you need to set
ClearAutomationEventsHelper.IsEnabled = false;
at the start of your application to test so it exposes way more things (like tabs) to FlaUI.

Use WPF component from external .exe

Here's the situation:
We have an existing .NET executable that contains an application using WPF components (dialogs and forms). This executable was created using Gupta Team Developer 6.1, but I'm not sure that is relevant to my question. We'd like to re-use some of these forms in a C#-application, but this is proving difficult.
When we include the external components, either in XAML or by instantiating them in code, they look OK (i.e. fields, buttons, layout etc.), but the event wiring seems to be missing. Nothing happens when pressing buttons and tables/grids are empty.
I've read previous articles on this site on using external WPF components, but they all mention external assemblies compiled as control libraries. Are we trying to do something that's not really possible?
P.S As an experiment we've tried to instantiate the App-object from the executable directly and this brings up a fully functional version of the entire application (well, duh), but we'd really like to be able to pick and choose from the individual forms/dialogs.

Can I dynamically add a user control to a silverlight application without recompiling it?

I have a silverlight application with several menu buttons, each of which opens up a user control in a center "work space" area. It works fine. Now what I'd like to do is make some more user controls, compile them into a dll, and through say, a configuration file, have the silverlight app add a new menu button and make it make one of those new controls appear. The difficult part is, I'd like to be able to do this without recompiling the silverlight app. I'd like another developer to be able to make a user control that does some things, compile it into a dll, and drop it into the silverlight directory with some changes to a config file to get the main app to load it in. Is there a way I could do this?
Since noone else has replied yet:
What you want to do is reflect classes form a third-party dll at runtime. This is possibly too big a subject for SO, and all I can really recommend is looking up examples of it, and maybe the msdn section on it.
You'll also want to look up serialization and deserialization in C# and silverlight (this question might be a good start).
Sorry I can't be more help than that, but hopefully someone more experienced will weigh in with a useful article or some such.
Good luck :)

How to list all the elements of an application?

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().

How do read/interact with an old ActiveX SSUltraGrid using UIAutomation

I am investigating automated testing of an old Win32 application that used ActiveX controls. I am spiking use White (from Thougthworks) that uses Microsoft UIAutomation. I can find the AutomationElement related to the control, but how do I interact with it?
Spy++ sees the grid control as a single window, so I can't talk to rows, columns, or cells directly. How do I talk to the SSUltraGrid control from my test code?
Cheers
Nigel
The basic problem with some ActiveX and other custom controls like SSUltraGrid is what you mentioned, they're presented as just one window. So unless they've provided an API that makes them "friendly" to your GUI automation tool, you'll always face this challenge. Of course many companies offer newer versions of their products that are friendlier to UI Automation than before... perhaps upgrading the control is worthwhile...
Failing that... what the test engineers at my job have told me is that when they encounter that situation, if there are well known keystrokes to invoke the activity they desire, they send keystrokes to the control window. If they're lucky enough to have things in a fixed location, they might even be able to get away with sending mouse events. However, that's dicey at best.

Categories