Hosting External App in Wpf Window

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



Leave a reply



Submit