Show application inside form

  • Thread starter Thread starter Thomas
  • Start date Start date
T

Thomas

I'm trying to show an application inside a form by using
process.start("ApplicationNamn.exe"). After starting the
process the new window should be locked inside a form as
maximised. Unfortunately are there no activeX components
devloped for the application I'm working with. Do someone
have some suggestions how to proceed? or were to look?

Thomas
 
Hi,

It's a kind of a hack, but you can change the parent window handle of your
application to the form handle.

This example should get you started (some code has been left out):

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace SetParentExample
{
public class Form1 : System.Windows.Forms.Form
{
[DllImport("user32.dll")]
private static extern int SetParent(IntPtr hWndChild, IntPtr
hWndNewParent);

[DllImport("User32")]
private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

private const int SW_MAXIMIZE = 3;

Process p = new Process();

private void Form1_Load(object sender, System.EventArgs e)
{
// start your application
p.StartInfo.FileName = "NOTEPAD.EXE";
p.StartInfo.UseShellExecute = true;
p.Start();

// change parent window and maximize inside the form
SetParent(p.MainWindowHandle, this.Handle);
ShowWindow(p.MainWindowHandle, SW_MAXIMIZE);
}
}
}

Regards,

Gabriele
 
Yes, it should work as well. If you try the sample with CMD.EXE instead of
NOTEPAD.EXE you'll see that the console window appears inside the form.
 
Do you know if similar trick is possible with Console window?
Is it possible to set in same way position and location of Console in parent
form?

Thanks!
 
Yes it appears, but doesn't show Console.Write output.

Fortunately, GetConsoleWindow (win32 api) did the trick.

Thank you for hint!

Rgds
Alex
 
Back
Top