'newbe' Embed an applicaion within my form?Help.....
Hello just regestred as I have just started to learn C# at college on the HNC. I am trying to write an application for my workplace. What I would like to do is to run other applications within my form, does anyone have any ideas?
AlanPosted Nov 29, 2008, 9:03 AM
There is a way to run notepad from within your form though you have to call a number of Win32 API functions to do so.
Here's some code I wrote a while back in response to a similar question on another forum. For some reason which I couldn't fathom,I could never get it to overlay properly though you might have better luck with your application:
// win32 definitions needed
const int GWL_STYLE = -16;
const int WS_VISIBLE = 0x08000000;
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth,
int nHeight, bool bRepaint);
// code to start notepad and host within main app window (place within a method)
Process p = new Process();
p.StartInfo.FileName = "notepad.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.Start();
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, this.Handle);
SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
MoveWindow(p.MainWindowHandle, 0, 0, this.Width, this.Height, true);
CGPosted Nov 29, 2008, 6:14 AM
AlanPosted Nov 28, 2008, 7:20 AM
CGPosted Nov 28, 2008, 7:09 AM
AlanPosted Nov 28, 2008, 7:05 AM
I'd check out the System.Diagnostics.Process class:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
For example, to run notepad from your Windows Forms application, is as simple as:
Process.Start("notepad.exe");