1

My Solution has 3 wpf applications, each an exe. The main exe (called as Parent) has a menu from where I want to call (open) the other two exes. I am able to do that by process.start (myexe) and assign it to the window handle of the parent application.

However, I want the new exe to be opened inside a particular content control (or a tabitem, or a prism region) of my wpf mainwindow. I also tried using Prism but I am unable to assign the exe's mainview to a region.
I am not able to get the view (usercontrol) from child process's handle and assign it to a contentcontrol of the main view of the parent application.
The final result in any case should have multiple exes opened in the task manager (which I have achieved) but they are floating inside the Parent App, My main intent is to show them inside some designated control in the main app.



Can someone guide how this can be achieved?

  • 2
    Do you really need it to be different exes? If you just want to include a view in another form you can do it with forms in one project. – Pati K Feb 06 '19 at 10:51
  • yes the main requirement is separate exes that go to particular container control in the main app. I know how to include views from same or different projects in main app. – chiku coder Feb 06 '19 at 13:16
  • 1
    This whole plan sounds like a bad idea to me. A wpf usercontrol doesn't have a hwnd and afaik you'd need one to embed anything in a wpf control. If you instead can work with just the mainwindow, you could give this approach a go https://www.codeproject.com/Tips/673701/Hosting-EXE-Applications-in-a-WPF-Window-Applicati – Andy Feb 06 '19 at 16:14

1 Answers1

0

If you have absolutely no choice then you can use something like this which is already made for you. https://www.codeproject.com/Tips/673701/Hosting-EXE-Applications-in-a-WPF-Window-Applicati

You define the control that will host the application in xaml.

<local:AppControl x:Name="appControl" />

Then in the code behind (or another way) you specify the path to the exe you want embed:

appControl.ExeName = "notepad.exe";
this.Unloaded += new RoutedEventHandler((s, e) => { appControl.Dispose(); });

There's also this Hosting external app in WPF window which is very relevant to what you want to do.

Hastaroth
  • 41
  • 1
  • 2
  • 7
  • Thanks for the links. I have already followed them and they indeed open the exes in my main app. But here the requirement is to show separate exes in one container app at some designated space (I again repeat an container like grid having two content controls or a tabcontrol). So if click on button 1 it opens app1 on tab 1 and so on. The final idea is to show the exes running in separate tabs. We already are doing so by rendering the views from different applications but now the requirement is to have separate exes . I am interested to know if it can be done or not. – chiku coder Feb 07 '19 at 08:09
  • As far as I can tell there is nothing preventing you from having multiple AppControls in tabs or grids. Did you try it with the library? – Hastaroth Feb 07 '19 at 15:21
  • Thanks for pointing out the Library. I tried that out too. In the client app, i added two row Grid and tried setting the exe property. The MoveWindow is still using coordinates to place the new exe instead of assigning it inside the appcontrol. – chiku coder Feb 08 '19 at 08:24