Embed an application in a RadPane.

2 posts, 0 answers
  1. Oreades
    Oreades avatar
    4 posts
    Member since:
    Nov 2013

    Posted 17 Mar Link to this post

    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!

  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 21 Mar Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top