This is a migrated thread and some comments may be shown as answers.

Embed an application in a RadPane.

1 Answer 157 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Oreades
Top achievements
Rank 1
Oreades asked on 17 Mar 2016, 06:01 PM

Hello.

I need to place an application window (for example, notepad.exe) embedded within a RadPane.

I've managed to do in a Window application but do not get into a RadPane.

XAML user control located in the RadPane:

 
<UserControl x:Class="EmbeddedApp"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:I3TV.GAMA.WPF.UI.Media.Player.Player"
             d:DesignHeight="300"
             d:DesignWidth="300"
             mc:Ignorable="d">
    <StackPanel x:Name="AppContainer" />
</UserControl>

[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
 
[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
public static extern int SetWindowLongA([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd, int nIndex, int dwNewLong);
 
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
 
private const int GWL_STYLE = (-16);
 
private const int WS_VISIBLE = 0x10000000;
 
public EmbeddedApp()
{
    InitializeComponent();
    this.Loaded += new RoutedEventHandler(OnVisibleChanged);
}
 
/// <summary>
/// Create control when visibility changes
/// </summary>
/// <param name="e">Not used</param>
protected void OnVisibleChanged(object s, RoutedEventArgs e)
{
    // If control needs to be initialized/created
    if (_iscreated == false)
    {
        // Mark that control is created
        _iscreated = true;
 
        // Initialize handle value to invalid
        _appWin = IntPtr.Zero;
 
        try
        {
            var procInfo = new System.Diagnostics.ProcessStartInfo(this.exeName);
            procInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(this.exeName);
            // Start the process
            _childp = System.Diagnostics.Process.Start(procInfo);
 
            // Wait for process to be created and enter idle condition
            _childp.WaitForInputIdle();
 
            // Get the main handle
            _appWin = _childp.MainWindowHandle;
        }
        catch (Exception ex)
        {
            Debug.Print(ex.Message + "Error");
        }
 
        // Put it into this form
        var helper = new WindowInteropHelper(Window.GetWindow(this.AppContainer));
        SetParent(_appWin, helper.Handle);
 
        // Remove border and whatnot
        SetWindowLongA(_appWin, GWL_STYLE, WS_VISIBLE);
 
        // Move the window to overlay it on this window
        MoveWindow(_appWin, 0, 0, (int)this.ActualWidth, (int)this.ActualHeight, true);
 
    }
}

 

Thank you!

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 21 Mar 2016, 07:00 AM
Hello,

You can check the following example in our SDK Repository which demonstrates how to embed WinForms application inside RadDocking control:
https://github.com/telerik/xaml-sdk/tree/master/Docking/WinFormsInsideDocking

Regards,
Yana
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Docking
Asked by
Oreades
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or