G
Guest
I've searched around for this and have found some VB examples but 1) I'm not
sure that they're VB.NET and 2) If they are VB.NET, then they're not working
once ported to C#. I'll be doing this in .NET 2.0 w/ VS.NET 2k5
Below is my code:
#region WinAPI Functions
[DllImport("user32.dll")]
public static extern IntPtr GetParent(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr
hWndNewParent);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr GetWindow(IntPtr hwnd, int wCmd);
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hwnd, string lpString, int
cch);
[DllImport("user32.dll")]
public static extern long GetWindowThreadProcessId(IntPtr hwnd, long
lpdwProcessId);
[DllImport("user32.dll")]
public static extern bool LockWindowUpdate(IntPtr hwndLock);
[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
public static extern bool DestroyWindow(IntPtr hwnd);
[DllImport("user32.dll", EntryPoint = "SetFocus")]
public static extern IntPtr ApiSetFocus(IntPtr hwnd);
[DllImport("kernel32.dll")]
public static extern bool TerminateProcess(IntPtr hProcess, int
uExitCode);
[DllImport("kernel32.dll")]
public static extern IntPtr GetCurrentProcess();
#endregion
Those functions were listed in a VB solution as the ones to use. Then for a
btnLaunch in my MDI form:
private void btnLaunch_Click(object sender, EventArgs e)
{
if (ofdApp.ShowDialog(this) == DialogResult.OK)
{
string appCommand = ofdApp.FileName;
m_process = new System.Diagnostics.Process();
m_process.StartInfo = new
System.Diagnostics.ProcessStartInfo(appCommand);
Program.LockWindowUpdate(Program.GetDesktopWindow());
if (m_process.Start())
{
Program.SetParent(m_process.Handle, this.Handle);
}
Program.LockWindowUpdate(this.Handle);
}
}
If anybody's got an idea as to how to do this in C# 2.0 or has an example
please let me know. Thanks!
sure that they're VB.NET and 2) If they are VB.NET, then they're not working
once ported to C#. I'll be doing this in .NET 2.0 w/ VS.NET 2k5
Below is my code:
#region WinAPI Functions
[DllImport("user32.dll")]
public static extern IntPtr GetParent(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr
hWndNewParent);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr GetWindow(IntPtr hwnd, int wCmd);
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hwnd, string lpString, int
cch);
[DllImport("user32.dll")]
public static extern long GetWindowThreadProcessId(IntPtr hwnd, long
lpdwProcessId);
[DllImport("user32.dll")]
public static extern bool LockWindowUpdate(IntPtr hwndLock);
[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
public static extern bool DestroyWindow(IntPtr hwnd);
[DllImport("user32.dll", EntryPoint = "SetFocus")]
public static extern IntPtr ApiSetFocus(IntPtr hwnd);
[DllImport("kernel32.dll")]
public static extern bool TerminateProcess(IntPtr hProcess, int
uExitCode);
[DllImport("kernel32.dll")]
public static extern IntPtr GetCurrentProcess();
#endregion
Those functions were listed in a VB solution as the ones to use. Then for a
btnLaunch in my MDI form:
private void btnLaunch_Click(object sender, EventArgs e)
{
if (ofdApp.ShowDialog(this) == DialogResult.OK)
{
string appCommand = ofdApp.FileName;
m_process = new System.Diagnostics.Process();
m_process.StartInfo = new
System.Diagnostics.ProcessStartInfo(appCommand);
Program.LockWindowUpdate(Program.GetDesktopWindow());
if (m_process.Start())
{
Program.SetParent(m_process.Handle, this.Handle);
}
Program.LockWindowUpdate(this.Handle);
}
}
If anybody's got an idea as to how to do this in C# 2.0 or has an example
please let me know. Thanks!