Embed an App into a Window

How to embed web application into windows app with custom behavior

If you are using WPF, you can create you window with something like this (xaml):

<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
Title="MainWindow" Left="100" Top="200" Height="350" Width="525" PreviewKeyDown="Window_PreviewKeyDown">
<Grid x:Name="grdBrowserHost">
</Grid>
</Window>

WindowStyle attr None means "borderless with no titlebars" window. Left and Top are for position, and Width and Height are self-explanatory. All those properties can be accessed via code-behind with simple this.Width, etc... PreviewKeyDown I put here because in this example (as you will see), Topmost property will be changed from code behind (dynamically).

Code-behind should look something like
using System;

using System.Windows;
using System.Windows.Input;

namespace WpfApplication2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

System.Windows.Controls.WebBrowser browser = new System.Windows.Controls.WebBrowser();
// you can put any other uri here, or better make browser field and navigate to desired uri on some event
browser.Navigate(new Uri("http://www.blic.rs/"));
grdBrowserHost.Children.Add(browser);
}

private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
}
else
{
this.Topmost = !this.Topmost;
}
}
}
}

In this example I have created default WebBrowser control for showing html. If you want some other web rendering engine you must find 3rd-part control and include it in your references. For webkit, you can check How to use WebKit browser control in WPF

How to embed the window of another application in my application

You can embed it as a resource in your exefile. But you have to extract it and run it. You can run it hidden as prev poster noted.

How to do that? Download ResHacker to embed the resource.

Here's a sample that includes vb6 source code for a self extracting installer. Don't install it as what it installs doesn't work on post win 2000 versions. The installer part does work any version.

http://mvps.org/serenitymacros/images/webview.zip

Embed Win32 App inside a UWP App


In my scenario i need to embed (i.e open within) a Win32 GUI app in UWP GUI app or vice versa

For extend the Win32 GUI with UWP GUI, which is impossible currently. You need to create a Windows app package for your desktop application by using the Desktop Bridge firstly. Details for how to do you could reference Package an app using the Desktop App Converter. And then you could Extend your desktop application with modern UWP components. This guide contains details about how to do and a sample.

But if you mean you want to display the Win32 and UWP UI inside the same window, unfortunately it is impossible currently. Details please check this similar thread.

Embed an application within a WPF Window

Here is the code, the problem was that you need to set position, width, height and repaint the child window in the new parent window.

public void CapturarApp()
{
hWndApp = ScreenFuntion.getWindow("Notepad");
if (hWndApp.ToInt32() > 0)
{
ProgramsEncrustForm.MoveWindow(hWndApp,
0, 0,
Int32.Parse(Width.ToString()),
Int32.Parse(Height.ToString()), 1);
ProgramsEncrustForm.SetParent(hWndApp, new WindowInteropHelper(this).Handle);
}
else
{
hWndApp = IntPtr.Zero;
}
this.Show();
}

And here is the method to move and repaint the window

[System.Runtime.InteropServices.DllImport("user32.dll")]
public extern static int MoveWindow(IntPtr hWnd, int x, int y,
int nWidth, int nHeight, int bRepaint);

Embed an app into a window

the only supported and reliable mechanism is XEmbed, but it requires the embedded app to cooperate. Without a cooperating app, you're in a world of scary hacks.

The basic thing you need to do is XReparentWindow() but the problem is that you're fighting the window manager which will also want to reparent the window. You're also potentially confusing the app, which will be expecting ICCCM and EWMH behavior, and expecting the parent window to be a WM frame.

Really old GNOME 1.x versions of gnome panel had a swallow feature you could try to steal hacks from maybe.

Without pretty extensive X knowledge this will be painful, and even
with it's not necessarily possible to make 100% reliable.



Related Topics



Leave a reply



Submit