ExeContainer 0.0.1
See the version list below for details.
dotnet add package ExeContainer --version 0.0.1
NuGet\Install-Package ExeContainer -Version 0.0.1
<PackageReference Include="ExeContainer" Version="0.0.1" />
<PackageVersion Include="ExeContainer" Version="0.0.1" />
<PackageReference Include="ExeContainer" />
paket add ExeContainer --version 0.0.1
#r "nuget: ExeContainer, 0.0.1"
#:package ExeContainer@0.0.1
#addin nuget:?package=ExeContainer&version=0.0.1
#tool nuget:?package=ExeContainer&version=0.0.1
ExeContainer
A modern .NET library for embedding external executable applications into your Windows Forms or WPF applications. This project is based on and improved from bitzhuwei/AppContainer.
🚀 Features
- Cross-Platform Support: Supports both .NET Framework 4.7.2 and .NET 8.0
- Dual UI Framework Support: Works with both Windows Forms and WPF
- Modern Async/Await: Built with modern C# async patterns for better performance
- Automatic Window Management: Handles window resizing and lifecycle automatically
- Error Handling: Robust error handling with detailed exception information
- Process Lifecycle Management: Automatically manages embedded application lifecycle
📋 Requirements
- Windows 10/11 or Windows Server 2016+
- .NET Framework 4.7.2 or .NET 8.0
- Visual Studio 2019+ or .NET CLI
🛠️ Installation
NuGet Package (Recommended)
# For Windows Forms applications
Install-Package ExeContainer
# For WPF applications
Install-Package ExeContainer
Manual Installation
- Clone this repository
- Build the solution
- Reference the
ExeContainer.dll
in your project
📖 Quick Start
Windows Forms Usage
- Add the control to your form:
using ExeContainer;
public partial class Form1 : Form
{
private ExeContainerWinform exeContainer;
public Form1()
{
InitializeComponent();
exeContainer = new ExeContainerWinform();
this.Controls.Add(exeContainer);
exeContainer.Dock = DockStyle.Fill;
}
}
- Embed an application:
private async void btnEmbed_Click(object sender, EventArgs e)
{
string exePath = @"C:\Path\To\Your\Application.exe";
bool success = await exeContainer.EmbedProcess(exePath);
if (success)
{
MessageBox.Show("Application embedded successfully!");
}
else
{
MessageBox.Show("Failed to embed application.");
}
}
WPF Usage
- Add the control to your XAML:
<Window x:Class="YourNamespace.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:execontainer="clr-namespace:ExeContainer;assembly=ExeContainer"
Title="MainWindow" Height="450" Width="800">
<Grid>
<execontainer:ExeContainerWpf x:Name="wpfContainer" />
</Grid>
</Window>
- Embed an application:
private async void btnEmbed_Click(object sender, RoutedEventArgs e)
{
string exePath = @"C:\Path\To\Your\Application.exe";
bool success = await wpfContainer.EmbedProcess(exePath);
if (success)
{
MessageBox.Show("Application embedded successfully!");
}
else
{
MessageBox.Show("Failed to embed application.");
}
}
🔧 Advanced Usage
Custom Window Sizing
The embedded application automatically resizes with the container, but you can also manually control the size:
// For Windows Forms
exeContainer.Size = new Size(800, 600);
// For WPF
wpfContainer.Width = 800;
wpfContainer.Height = 600;
Error Handling
try
{
bool success = await exeContainer.EmbedProcess(exePath);
if (!success)
{
// Handle embedding failure
Console.WriteLine("Failed to embed application");
}
}
catch (Exception ex)
{
// Handle exceptions
Console.WriteLine($"Error: {ex.Message}");
}
📁 Project Structure
ExeContainer/
├── ExeContainer/ # Main library
│ ├── ContainerHelper.cs # Core embedding logic
│ ├── Win32Api.cs # Windows API declarations
│ ├── ExeContainerWinform.cs # Windows Forms control
│ └── ExeContainerWpf.xaml # WPF control
├── ExeContainer.WinformDemo/ # Windows Forms demo
├── ExeContainer.WpfDemo/ # WPF demo
└── README.md
🎯 Demo Applications
The repository includes two demo applications:
- ExeContainer.WinformDemo: Windows Forms demonstration
- ExeContainer.WpfDemo: WPF demonstration
To run the demos:
- Open the solution in Visual Studio
- Set either demo project as the startup project
- Build and run
- Click "Browse" to select an executable file
- Click "Embed" to embed the application
🔍 How It Works
ExeContainer uses Windows API calls to:
- Start the target process with minimized window style
- Wait for the main window handle to become available
- Set the parent window using
SetParent
API - Remove window borders and adjust styles
- Resize and position the embedded window
- Handle window lifecycle automatically
⚠️ Limitations
- Only works on Windows platforms
- Some applications may not embed properly due to their internal window management
- Console applications cannot be embedded
- Applications with multiple main windows may behave unexpectedly
- UAC-elevated applications may require special handling
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
This project is based on the original work by bitzhuwei/AppContainer. We've modernized the codebase with:
- Modern .NET support (.NET 8.0)
- Async/await patterns
- Better error handling
- Improved WPF support
- Enhanced documentation
📞 Support
If you encounter any issues or have questions, please:
- Check the Issues page
- Create a new issue with detailed information
- Include your .NET version and target framework
Note: This library is designed for embedding external applications into your own applications. Please ensure you have the necessary permissions and licenses to embed third-party applications.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.2
- No dependencies.
-
net8.0-windows7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release with support for .NET Framework 4.7.2 and .NET 8.0