How can I access objects in other applications with C#? - c#

I want to access the objects and their properties in a similar way to how automation tools access them in their "UI Map" functionality. I'm assuming there's an assembly reference that will give access to running processes and whatever objects exist for that process.
Specifically, I need to access a few label control text properties in another running application.
Also, sorry if this is a duplicate - I looked around, but I'm not sure what keywords would get me to what I need.

This is not a common practice in C#. The term that you are looking for is to "spy" another window/application/process. There are several resources here in StackOverflow talking about this. For example:
How can I get functionality similar to Spy++ in my C# app?
To access a control in another Win32 form you need to look for the handle of that element.

For WPF applications, the UI Automation libraries present in .NET 4.5 make this way simpler: http://msdn.microsoft.com/en-us/library/ms747327.aspx
For older winforms applications, you'll have to actually utilize pInvoke on the User32 API. The example link Pete gave you in the comment on your question will help guide you in that direction: http://www.pinvoke.net/default.aspx/user32.enumwindows

Related

Unable to set start page (to windows form) in MFC application

At a broader level, I'm converting a MFC application (MFC 6.0) into Windows Forms application (Visual Studio 2013). I read certain blogs that describes that this conversion is possible. By this conversion I can re-use code written in MFC, only I will need to create UI. However I will need to understand the previous code and may need to re-write it a bit.
I got the motivation from here and here.
I have performed following steps so far.
Opened Visual C++ 6.0 project in Visual Studio 2013.
Build it successfully.
Then added CLR support to it, and fixed errors.
Added a Windows form, and added controls to it. As mentioned here.
Added functionality and build it successfully.
Now when I run this application, then it still point to old MFC window.
I'm missing certain settings which will change the rendering window from MFC to WindowsForm. What am I missing here?
Addition to that, I see problem with this approach as described by #Roger in comments, and I understand that. So, I wanted to know for any tool/utility which may convert legacy code into C#. Does such utility available?
TIA.
The code you are referring to seems suitable for amending a MFC application with a few forms as child windows to make use of .NET features. However, the main window is another story. You wrote the application is huge, so I suppose you don't want a simple form as your main window and rather have some kind of MDI interface in mind. If you replace the CMainFrame in the legacy MFC application, it just doesn't make sense to maintain an old CWinApp class. Anyway, if you are hell-bent on going down that path, you may want to have a look at an old CodeProject articel (.NET1.x, .NET2.x) to get a better grasp at the whole concept.
But as Roger already suggested, it would be a wise choice to find a nice GUI framework, perhaps even WPF instead of WindowsForms, and do a GUI rewrite -- especially if one part of the motivation for the conversion is to move to newer UI concepts. If your C++ program logic is well separated in your MFC project, put it in a COM server and make use of interoperability.

Buttons to Message Box in Visual Studio 2008

Is it possible to add custom buttons (or) User defined buttons inside Message Box in Visual Studio Windows Forms application ?
Here's a quick guide to making a custom dialog box, which is going to be the ideal solution for you in this scenario, in my opinion.
The simple answer is: no it's not.
The long answer is that it's not possible using the managed API but it may be possible using the Win32 API. Here's a good tutorial on using Windows Hooks to customize the operating system message box dialog.
The .net MessageBox class does not offer such functionality. However, the native Win32 API does so through the TaskDialog API. The main advantage of this approach, as opposed to writing a custom dialog, is that you will be using a native system component and so your dialog will feel at home on the platform.
A very simple example of the task dialog looks like this:
And there is lots of scope for much more complexity, as is explained in the link above.
You'll need to p/invoke to this function. It's one of the more messy functions to call so expect a little work before you have a working solution. You can find some C# code to wrap it up here, but I can't say that I personally have experience of this.

Is this a WinForm Control?

I'm just wondering if this control can be used in my WinForm application. Please refer to the image below:
That particular control is not in .NET. There are, however, third party controls that provide the same (or at least very similar) appearance. One example is the DevExpress NavBar.
(And no, I am in no way affiliated with DevExpress; I've just used their products for years and have been happy with them)
This control was not written in managed code, so it not consumable by .NET directly.
I think it's rich component in C#.It's LeftTab

How to embed a C# User Control into Windows Explorer?

Is it a way to embed my User Control into Windows Explorer? Please tell me if you have any resources about this.
Thanks,
Weipeng
While you can, and there are a number of examples of how to do this. I recommend that you do NOT create shell extensions in managed code.
There are a number of reasons for this. For example, you now have to pull the entire managed runtime into the shell namespace. This means your explorer instance will use a lot more memory than is necessary.
However, the single biggest reason is that you cannot control which version of the namespace might already be in the shell process space when your control is loaded. See this article for why it's a bad idea.

How to display a form inside another form like Visual Studio

How does Visual Studio and other similar programs display a form in their IDE?
Is it possible to achieve the same or a similar effect using C# or VB.NET?
Please see the picture below to get what I mean.
If you are talking about hosting a Winforms editor in your code, it is entirely possible and is actually built in to the .NET framework!
The Essence is the IDesignerHost interface. The whole system is complicated, but can be done (I have done it in production code for runtime layout configuration editing). There is a sample of code from Microsoft here.
I'm sure if you search fir 'IDesignerHost' you'll find enough reference material to figure it out.
Are you speaking about UI creating tools?
Refer to http://www.icsharpcode.net/opensource/sd/ - SharpDevelop for deep dive. It's open sourse, so you'll be able to find out more details.
I believe what you want is a multiple document interface (MDI) see http://msdn.microsoft.com/en-us/library/ms973874.aspx for more info.

Categories

Resources