Hosting WPF/Surface application within WPF/Surface application - c#

I am trying to create a parent WPF/surface application which will host multiple WPF/surface applications. I am looking for some pointers of how to implement such functionality. Was reading http://msdn.microsoft.com/en-us/library/ms742522.aspx but it talks about hosting Win32 content in WPF and vice versa.
My idea is to have something similar to MDI forms where you have a main form and you can instantiate multiple child forms.
In my case, these would be different applications which will be launched using a config file and loaded within the main application.
Also, since is there a way to ensure that the main window's process memory is not hogged by the child process initiated.
Edit:
The host application will launch different applications based on what user selects. One can say its like an application launcher which are build on WPF/Surface touch SDK. Now once the application is launched the launcher goes in the background(except showing small button to bring it forward again at some point later) and when the user ends the current application launcher comes back again in foreground. The only interaction i feel which is necessary is knowing the launched application is terminated or invoking applications in a limited screen area. If someone has seen the Microsoft surface application launcher, even when the application is launched there are corner buttons which bring the app launcher to foreground.

I would first look at using Microsoft Prism, specifically the Modularity namespace.

Except for the "different applications" part, it sounds like a classic case for MVVM. Are these "different applications" actually separate applications, or could they simply be separate projects within the same application? That may simplify the choice of presentation.
I suppose you could still have a View called "Host" that presents a different app.
Of course, WPF doesn't have the concept of MDI, but you can open multiple, non-modal windows.
It really depends on what you mean by "hosting". Does the main window need to somehow handle and/or interact with the other applications, or is it just a launching pad for other applications?

I followed this approach to solve this problem. The launcher was not hosting the application within itself but would launch a new application and hide itself.
Steps I followed:
The main launcher application will run in Kiosk mode i.e always on top/no option to close by capturing the close event/No instance shown in taskbar/no title bar/killing the explorer.exe/hiding the taskbar.
The launcher populates a horizontal listbox (data templated for UI) which lets occupied main center area of screen and can be scrolled either ways.
When user selected an item on listbox, click/tap event a separate process is launched with launcher window's visibility set to hidden and a small button(basically a window with just a button inside and size set to height/width of button) created on the either corner of the screen with always on top option.
The functionality of button is to minimize the current working application and set visibility of launcher back to visible and setting the focus to this window.
Since the process is launched by launcher, i trap the close event for the launched window to know user ended the application and then again pop up the launcher back.

Related

C# Embedd A Non-Winforms Application into a Winform Application

I want to embedd an application (Hikvision iVMS-4200) into my winform .net application. The application appears to use custom rendering for its GUI, and a loading screen appears before the main window is launched.
In more detail, I want the window of this app to be confined within the window area of my application in a locked position (user can't move the embedded window), and display other things in the same parent window (for example a picture).
I have tried solutions such as this. It worked perfectly, but only with notepad. This solution doesn't work with the application I want (the process is opened successfuly but it is in a completely independant window).
My guess is that the app (again, Hikvision iVMS-4200) uses OpenGL for a custom GUI or another type of non-native GUI library. As a though, shouldn't any application on windows have atleast a single main window? could I access and edit its position and parenting properties? Any solution would be highly appreciated.

How to track other application's event

My client has a previously developed windows application which they don't have the source code. They need a dash board in the application. This application has a option to add and call third party application, so I developed a dash board screen application with all the data they needed and add it in their application. But they wanted to see the dash board in side the main screen (just like MDI from and child form). I am thinking I can place my new application in such way that it will look like a child form but I need to track the minimize, maximized and close event of the main application so can change my application accordingly. Is it possible?
For the last part of your question if you want the new app intercepts when the first one being maximized or minimized, you can use global hooks.you can try this link:
https://www.codeproject.com/Articles/802412/Global-Interceptable-Program-and-System-Hooks-in-N

WPF - View getting minimized during navigation

I have a WPF application which behaves weird when another application is also opened. 'Another' application is developed using Panther. WPF apps behaves correctly with all other apps in the machine.
While both the applications opened, and when we click next on the WPF app, the app getting minimized even though its active as per windows active event.
WPF application is built using galasoft and follows slightly different approach in navigation compared to the pattern available when we search.
We initiate the Page from app.xaml.cs and based on the click, we invoke currentPage.Hide() and nextPage.Show() methods. All the navigations are written within App.xaml.cs file. Through a delegate the button click will be passed to app.xaml.cs file and the pages are switched.
Did anyone else face similar kind of issues?
Finally, I managed find an answer/work around to this issue.
In the existing design, the sequence of actions were Hide() the current view and Show() the next view.
Now, we modified the sequence to perform Show() the next screen first and then hide() the current screen. This way, the window was kept active and was visible to the user.

Set Owner of wpf window by window of other application, is it possible?

I would like to make an application by wpf which could overlay a specific windows application.
It means, when I run my application and specify Notepad as target application. At that time, anytime Notepad application got focus, my application will take over the focus & prevent user handle directly Notepad.
It is quite simple in case of 2 windows in same application ( we can set owner of child window & showdialog)
So, I wonder that if it is possible to get the handle of window of other application to set owner for our application.
Thanks for any comments or discussion!
In the general sense, yes - it's possible. But you will have to use Platform APIs in order to obtain the handle of Windows that are not in your process.
Here's a list of Window-related Functions in the Win32 Platform API
You may then by able to make your WPF window appear on top of the other window. But just know that depending on your end goal this might not be the best way to achieve your desired results!

Creating new MDI Window in hosting application

I have an interesting case to solve:
I have a native (winapi) application, which uses MDI. This application allows me to extend itself with a simple scripting language. The scripts are launched on different thread than UI thread (although I can get the UI thread ID with appropriate functions). The scripting language also allow me to launch any c++ code (through LoadLibrary).
What I would like to achieve is to create a new window inside this application, which could host WPF and "attach it" as a MDI child window to MDI client (mdi area). Also, I would like this window to properly "talk" to MDI area, for example update list of windows in mdi menu.
So far, my first guess was to just create a WinForms window, host WPF inside, and then try to make it mdi child window by setting MDI client as it's parent (because my hosting application is not written in c#, I only have a handle, so I did this with User32.SetParent() P/Invoke). This worked almost well, after I attached my script thread to GUI thread, but I had few problems with it: the MDI menu with active windows did not update, the window did not interact correctly (it stayed on stop when it shouldn't etc.).
Then, I tried to set flags (style, exStyles) with SetWindowLongPtr. It changed my window's behavior a bit, but that was still not it.
Now I'm considering using CreateMDIWindow function, or doing it by SendMessage, according to docs sending message should create a window, even if I send it from different thread. The problem is, that this way would give me a native handle only, and I could not find (yet) any way of hosting WinForms / WPF inside it.
I'm curious if anyone tried to do something similar and had any results with it? Which way would be the best - trying to create a WinForms window and add it to MDI client, or create a native window and try to host WinForms in it (any particular way of doing that)?
Most answers for this question I have found are dealing with situation where hosting application is managed, so you can just set .MDIParent property, which won't work in this case I'm afraid.

Categories

Resources