RoyalApps.Community.ExternalApps.WinForms 0.1.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package RoyalApps.Community.ExternalApps.WinForms --version 0.1.0                
NuGet\Install-Package RoyalApps.Community.ExternalApps.WinForms -Version 0.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RoyalApps.Community.ExternalApps.WinForms" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RoyalApps.Community.ExternalApps.WinForms --version 0.1.0                
#r "nuget: RoyalApps.Community.ExternalApps.WinForms, 0.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RoyalApps.Community.ExternalApps.WinForms as a Cake Addin
#addin nuget:?package=RoyalApps.Community.ExternalApps.WinForms&version=0.1.0

// Install RoyalApps.Community.ExternalApps.WinForms as a Cake Tool
#tool nuget:?package=RoyalApps.Community.ExternalApps.WinForms&version=0.1.0                

External Apps Control

NuGet Version NuGet Downloads .NET Framework .NET

RoyalApps.Community.ExternalApps contains projects/packages to easily embed/use other external applications in an application. Screenshot

The ExternalAppHost control starts the configured process and embeds the application window into the control.

Warning:
What this control does is not exactly a Microsoft supported scenario! Please read Raymond Chen's blog post 'Is it legal to have a cross-process parent/child or owner/owned window relationship?' for more details. Spoiler alert: Yes, it's technically legal. It's also technically legal to juggle chainsaws!

Getting Started

Installation

You should install the RoyalApps.Community.ExternalApps.WinForms with NuGet:

Install-Package RoyalApps.Community.ExternalApps.WinForms

or via the command line interface:

dotnet add package RoyalApps.Community.ExternalApps.WinForms

Using the FreeRdpControl

Add Control

Place the ExternalAppHost on a form or in a container control (user control, tab control, etc.) and set the Dock property to DockStyle.Fill

Configuration

Create an instance of the ExternalAppConfiguration class and set the Executable property to the full path and file name of the application you want to embed.

Start

Simply call:

ExternalAppHost.Start(externalAppConfiguration);

to start and embed the application.

Close

To close the application, call:

ExternalAppHost.CloseApplication();

Depending on the application, you may get a confirmation dialog in case there are unsaved changes. You can set the ExternalAppConfiguration.KillOnClose property to true to forcibly quit the application by killing the process.

Note:
All processes which are started by the control will be closed/killed when the main application is closed or killed.

Detach Application Window

Once the application is started and embedded, you can detach the application window by calling:

ExternalAppHost.DetachApplication();
Re-Embed Application Window

To re-embed a detached application window, simply call:

ExternalAppHost.EmbedApplication();
Subscribe to Events
  • ExternalAppHost.ApplicationStarted is raised when the application has been started and embedded.
  • ExternalAppHost.ApplicationClosed is raised when the application was closed or killed (even outside of the hosting application).
  • ExternalAppHost.ApplicationActivated is raised when the application has been activated (received the input focus).
  • ExternalAppHost.WindowTitleChanged is raised when the window title of application window has changed.

Exploring the Demo Application

The demo application is quite simple. It has two tab controls (one left and one right) and a bottom panel for log output. Use the toolbar to enter an executable to embed. The Add drop down allows you to choose the left or the right tab control.

There are two embed-methods available:

  • Embed as Control: Only the client area of the external app window is embedded (without the main menu). The limitation of this method is that some applications may look like they are not focused/active.
  • Embed as Window: The whole window is embedded including the main menu (if available). The limitation of this method is that the ALT-TAB order may be incorrect.

In the Application menu you can detach and re-embed the active external application.

WinEmbed.dll

This project includes a dll called WinEmbed.dll (in the /lib folder) which handles most of the Windows native stuff. You can find the C/C++ code in the /src/WinEmbed directory. To build this dll from source, you need Visual Studio 2022 or later and also the WDK installed.

Acknowledgements

Special thanks to Alex for helping out with all the native code challenges.

Product Compatible and additional computed target framework versions.
.NET net5.0-windows7.0 is compatible.  net6.0-windows was computed.  net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0-beta2 43 10/9/2024
1.1.0-beta1 55 9/19/2024
0.3.5 202 6/22/2023
0.3.4 423 9/16/2022
0.3.3 409 9/15/2022
0.3.2 413 9/15/2022
0.3.1 397 6/20/2022
0.3.0 403 5/27/2022
0.2.10 409 5/23/2022
0.1.0 413 5/18/2022