Integrate the electronjs application inside the Wpf application

Nandini Nammi 41 Reputation points
2022-06-16T06:45:10.687+00:00

I have WPF application in that i want to render the electronjs app inside the window frame. actually, I am able to load electronjs application but as separate application not in window frame. Please find below code:

{
process = new Process();
process.StartInfo.FileName = @"xyz.exe";
process.StartInfo.Arguments = "-parentHWND " + hWnd.ToInt32() + " " +
Environment.CommandLine;
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.Start();

            process.WaitForInputIdle();  

}

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,762 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,858 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
805 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 48,506 Reputation points Microsoft Vendor
    2022-06-16T09:54:16.75+00:00

    Frame are used to jump between pages. You could use WindowsFormsHost to host other applications.

    Xaml:

    <Grid   x:Name="test">  
    
        </Grid>  
    

    Codebehind:

    using System;  
    using System.Diagnostics;  
    using System.Runtime.InteropServices;  
    using System.Threading;  
    using System.Windows;  
    using System.Windows.Forms.Integration;  
    
    namespace OpenEXEInWpf  
    {  
      public partial class MainWindow : Window  
      {  
    
        [DllImport("user32.dll")]  
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);  
    
        [DllImport("user32.dll", SetLastError = true)]  
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);  
    
        [DllImport("user32.dll")]  
        private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);  
    
        [DllImport("user32.dll")]  
        private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);  
        public IntPtr _appWin { get; set; }  
    
        private Process _childp;  
        public MainWindow()  
        {  
          InitializeComponent();  
          Loaded += (s, e) => LaunchChildProcess();  
    
        }  
    
        private void LaunchChildProcess()  
        {  
          string exeName = @"C:\**\PreventKeyboardInListview.exe";  
          var procInfo = new System.Diagnostics.ProcessStartInfo(exeName);  
          procInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(exeName);  
          procInfo.WindowStyle = ProcessWindowStyle.Minimized;  
          _childp = Process.Start(procInfo);  
          System.Windows.Forms.Panel _pnlSched = new System.Windows.Forms.Panel();  
          WindowsFormsHost windowsFormsHost1 = new WindowsFormsHost();  
          windowsFormsHost1.Child = _pnlSched;  
          test.Children.Add(windowsFormsHost1);  
          while (_childp.MainWindowHandle == IntPtr.Zero)  
          {  
            Thread.Yield();  
          }  
          _appWin = _childp.MainWindowHandle;  
          SetParent(_appWin, _pnlSched.Handle);  
        }  
      }  
    }  
    

    The result:

    212014-7.gif


    If the response is helpful, please click "Accept Answer" and upvote it.
     Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread. 

    [5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.