How would I host an external application in WPF?
Use a HwndHost to host the outside window in your application.
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);
Proper way of hosting an external window inside WPF using HwndHost
Right before calling 'SetParent' do this:
public const int GWL_STYLE = (-16);
public const int WS_CHILD = 0x40000000;
SetWindowLong(this.ChildHandle, GWL_STYLE, WS_CHILD);
Related Topics
How to Read an Entire File to a String Using C#
Using .Net 4.5 Async Feature for Socket Programming
Get the Serial Number of Usb Storage Devices in .Net Core 2.1
Asp.Net: Invalid Postback or Callback Argument
Get All Inherited Classes of an Abstract Class
Windows Application Startup Error Exception Code: 0Xe0434352
Scraping Webpage Generated by JavaScript with C#
Is Shifting Bits Faster Than Multiplying and Dividing in Java? .Net
Pass Complex Parameters to [Theory]
Can Itextsharp.Xmlworker Render Embedded Images
Automatically Set Appsettings.JSON for Dev and Release Environments in ASP.NET Core
Opening New Window in Mvvm Wpf
How to Update the Entityset - Because It Has a Definingquery and No <Updatefunction> Element Exist
C# (Mono) Linux Web Server Hosting with Consistent Static Variables Across Threads