Is it possible to use an XAML UI in a C++ program? - c#

I work on a 20 year old program which has alot of CDialogs inside. They are all called DoModal(). My users wish a more modern UI. In the past I have written C# apps with WPF and I wonder if I could add a new dialog into my old C++ program which is a XAML Dialog?
Alternativ:
I would like to seperate my current C++ program into 2 part: keeping the the logical part in C++ and redesign the Dialogs with XAML.
Is this directly possible?
Some time ago I had another project where I had a C# dll used in a C++ programm. Can I do it that way? How can I return the UI values and user actions to my C++ code then which has the logic about what to do with the inputs?

Related

Can I use WPF in win32 application?

Our company has a software in Alaska Xbase++. I want to modernize the GUI with WPF, without rewriting the software in C#. In this Alaska Xbase++ language, I have the ability to call C/C++ functions. I beleive, it is possible to create hybrid DLL, which has managed code, yet callable from unmanaged language, so doing a stdcall.
So my plan is that I write a wrapper DLL which manages all the things to create a WPF window and controls (and eventloop, everything). In this Alaska Xbase++ language I would call this wrapper DLL to create WPF window and controls in my Application.
For example:
-WpfWrapper.DLL In C# DLL (or application which listens data from Xbase++ app):
Function CreateWpfWindow(title) {..}
Function CreateWpfButton(caption, x, y, parent) {..}
C# DLL doing the "WPF things".
-In Alaska Xbase++ language I have a main window. But I want to modernize the GUI, I want to create some WPF window in that old Win32 app, so I call the DLL:
nHandle=CreateWpfWindow("My WPF window in Alaska Xbase++!")
CreateWpfButton("My button", 100, 100, nHandle)
This is just my thoughts.. Maybe there is other way. But I wonder is it possible to integrate IN ANY WAY WPF window and controls to an old Win32 Application? I beleive it does, either via some wrapper DLL or via some wrapper application.
Please give me some guidance how this could work. The created WPF window in my old app must be in focus, and above other windows. I have the HWND of my main window, I beleive it is neccesary.
I don't know what "Alaska Xbase++" is but my guess is the question you are asking is the reverse of what you should try. You shouldn't try to build a GUI application by calling into C# from some obscure programming environment. You should try to wrap your business logic, implemented in an obscure programming environment, in a DLL and call into that from C#.
Does Xbase++ expose a C interface?
If so make a custom DLL that calls your Xbase++ code and DllImport that DLL into a WPF application.

[C#/VB.NET]Communicating with closed source WPF Application

I've got a question regarding communcation with another application. I wrote a little application that checks if specific persons play a specific game (League of Legends) and if so, it creates something called the spectator code which looks like this:
"C:\Riot Games\League of Legends\RADS\solutions\lol_game_client_sln\releases\0.0.1.15\deploy\League of Legends.exe" "8394" "LoLLauncher.exe" "" "spectator spectator.eu.lol.riotgames.com:8088 nQCxZ8ayLm369T1DwEejG/QlEoR+JyZK 1407774989 EUW1"
In another application which is NOT developed by me called "BaronReplays" (http://puu.sh/7VBFj.png) (a WPF application) you can enter this code under File (http://puu.sh/7VBEM.jpg) -> Analyze Command and enter the Code (http://puu.sh/7VBGD.png), after that click ok. Then this game will be recorded. I want to automate the process of entering this code in my application, so that my application sends the code to BaronReplays (without it being maximized and using SendKeys). I tried SendMessage, but that didn't work out because the keys aren't recognized by BaronReplays... Do you think there's any other way to do what I want to do?
There is another way... As the WPF application is coded with the .NET framework, it is compiled to MSIL (Microsoft Intermediate Language). This means you can use a decompiler such as ILSpy to decompile and view the code of BaronReplays. This will give you some idea of how BaronReplays works so you can implement the same ideas into your own code project...
Hope this helped!
Rodit

getting control names of another exe

Hello all i have a rather specific Question and please consider my apologies if this is not a standard stack-overflow question ,
i need to know is it possible to get all control names of another exe e.g.
i have a c# application and i want to get all control names of another standalone application running on my computer say b.exe so if b.exe have a textbox and a button in it i want to have names of textbox and button in my c# exe and also i want to have a listener for click events of b.exe
till now whatever i have researched is nothing special actually i dont want full code snaps i just want a guideline can i do it thorugh pinvoke? or winapi? please explain what is pinvoke and winapi and is it possible through application hooking ? once again i need a guideline a way to follow so please help me out regarding this, i know i can get active windows name through pinvoke or winapi but my requirements are little high
1 . Access to control names:
Unfortunately I do not .NET (C#) but under Visual C++ this would be impossible.
The reason is: The controls do not have names in the executable any longer but the names are simply converted to numbers.
Example "myTextControl" would be 1234 in the executable. The information about the (original) name of the control gets completely lost while compiling.
2 . Accessing controls in other executables:
I think under .NET (C#) it is not as easy as under native programming languages (directly accessing the Windows API) but it is possible to access controls of other executables as long as you know the number (e.g. 1234).
Therefore you'll have to find out the window handle of the dialog window containing the control and then you can send messages to the control. Unfortunately many messages containing pointers will require some very tricky hacks. Messages without pointer work well.
3 . Creating a listener for a control in other executables:
Creating a listener (e.g. a click listener) on a control in another EXE is possible however very tricky: This would require writing a native (this means: not .NET / C#) DLL file which is then combined with the Windows API function "SetWindowsHookEx".
I do not think that a .NET API (required for C#) already exists that will do this because there are only few use cases for this.

Read a non C# Apps textbox using windows API from a C# Windows forms App

We have an old Windows 32 bit app written in C++ which does some stuff and displays the results in what resembles a textbox.
I have been ask to write an application in C# that reads the data out of the old app and then further process the data.
The issue is how do I read the textbox in the old application?
Someone told me I can get the “handle “of the application using windows API and step through the controls and then read each ones data! Is this true and if so how would I do it from C#?
This is to be a .Net 4 Windows forms Application.
Many thanks
You're probably going to have to use some Interop calls to accomplish this, specifically using a combination of FindWindow / FindWindowEx and SendMessage & WM_GETTEXT / WM_GETTEXTLENGTH.
Here is an article on the subject (in c++, however the same concepts will just need to be ported to use P/Invoke), it's a bit dated but I believe is should be very relevant to your situation.
You can use Spy++ application (comes with VisualStudio) to inspect your native application and find class name of control you are looking for.
Having that, you can get your native application's main window handle, which is easy if you are responsible for launching that application from your c# app:
...
var proc = Process.Start();
var mainWndHandle = proc.MainWindowHandle;
Otherwise, you will have to find other means of finding that window, fe. you can use function that I've described below to look for that window on your desktop (see msdn page for more info)
If you have all that, you can then get handle to the textbox control, using FindWindowEx function (as well as you can use it to find main window, by passing NULL as a hwndParent).
And when you have handle to this textbox, you can read it contents, by sending message of WM_GETTEXT.
If you haven't been PInvoke'ing much, you can check http://pinvoke.net/ for reference on how to call WINAPI function from your c# program.
Do you really need the UI of the C++ application? Because it will be very unconfortable to have 2 separate UIs with different message pumps. You'll need to syncronize this mess on the update of the value.
Why don't you properly strip the logic code from the C++ application and expose it in a Interop CLR project (C++/CLI)? If you don't need to add more features to the C++ app, it seems very straightforward to me

C# Making a Frontend to a Console Program?

I wrote a console program in c# that takes up to three files as input, and does some data calculations on them.
I'd like to make a simple frontend that allows the user to easily
import files - basically choose up to three files to be routed to the backend code
change settings - I have about 10 settings that I'm currently storing in an app.config file. maybe a simple settings box would be nice
see what's going on - the console program shows some status messages that might be useful to display on a GUI
I have practically no experience with windows forms or GUI design, so I really don't know where to begin. I compiled the backend stuff into a *.dll and am currently playing around in design mode of sharpdevelop...but i really have no idea how to get the two to work together.
any pointers would be greatly appreciated!
The usual pattern, in cases like these, is to make the main features of the application into a class library and call that from a wrapping executable, such as a console app, winforms app or webforms app (if possible). That way you can easily adapt the interface as needed and simply route input and output to and from the class library.
Edit: I realize this isn't a very indepth answer, but I hope it helps to get started at least, together with any other answer that may arrive.
If you want to get started with GUI design in .NET, I recommend you choose WPF (Windows Presentation Foundation). This is the latest technology released in the UI/graphics area by Microsoft and is where everything is heading now. (Windows Forms won't be obsolete for a long time, though it is surely but slowly becoming deprecated.) I noticed however that you are using SharpDevelop, which doesn't yet have real support for WPF (as far as I know), whereas it certainly does for WinForms. If there's any chance you can use Visual Studio, I recommend you begin by learning WPF. You have the advantage of not being confused by previous experience with the styles and methodologies of WinForms, so it would very much be the right way to go.
Whichever you wish to learn, the Getting Started page of WindowsClient.NET (the official MS site for both WinForms and WPF) would be a great resource. There's also a few MSDN articles on getting started with WPF.
Hope that helps.
Have you tried Visual Studio Express editions? They're free and come with a designer for either WinForms or WPF applications.
As a first pass you'll need 3 text areas for the filenames, with associated buttons to bring up the file open dialog (it doesn't actually open the file just returns the filename).
A label to display the status - updated from your worker code.
Then either the various radio buttons, check boxes etc for your configuration settings.
Oh and don't forget the "Start" button to set off your process.
If your process takes a while you ought to use a background worker thread. You can then implement a "Cancel" button to safely abort the process and tidy up if it goes wrong.
There will be optimisations and reorganisations that you can do once you've got it working.
Your question is quite indistinct. If you're asking about working with GUI, you should read some book on Windows Forms.
And if you're asking about how to put your dll in your new windows forms application, then you should just add a reference to it in winforms project's properties and then use classes from dll's namespace.

Categories