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("user 32.dll")]
public static extern IntPtr GetParent(IntPt r hwnd);
[DllImport("user 32.dll")]
public static extern IntPtr SetParent(IntPt r hWndChild, IntPtr
hWndNewParent);
[DllImport("user 32.dll")]
public static extern IntPtr FindWindow(stri ng lpClassName, string
lpWindowName);
[DllImport("user 32.dll")]
public static extern IntPtr GetWindow(IntPt r hwnd, int wCmd);
[DllImport("user 32.dll")]
public static extern int GetWindowText(I ntPtr hwnd, string
lpString, int cch);
[DllImport("user 32.dll")]
public static extern long GetWindowThread ProcessId(IntPt r hwnd,
long lpdwProcessId);
[DllImport("user 32.dll")]
public static extern bool LockWindowUpdat e(IntPtr hwndLock);
[DllImport("user 32.dll")]
public static extern IntPtr GetDesktopWindo w();
[DllImport("user 32.dll")]
public static extern bool DestroyWindow(I ntPtr hwnd);
[DllImport("user 32.dll", EntryPoint = "SetFocus")]
public static extern IntPtr ApiSetFocus(Int Ptr hwnd);
[DllImport("kern el32.dll")]
public static extern bool TerminateProces s(IntPtr hProcess, int
uExitCode);
[DllImport("kern el32.dll")]
public static extern IntPtr GetCurrentProce ss();
#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.ShowDia log(this) == DialogResult.OK )
{
string appCommand = ofdApp.FileName ;
m_process = new System.Diagnost ics.Process();
m_process.Start Info = new
System.Diagnost ics.ProcessStar tInfo(appComman d);
Program.LockWin dowUpdate(Progr am.GetDesktopWi ndow());
if (m_process.Star t())
{
Program.SetPare nt(m_process.Ha ndle, this.Handle);
}
Program.LockWin dowUpdate(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!
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("user 32.dll")]
public static extern IntPtr GetParent(IntPt r hwnd);
[DllImport("user 32.dll")]
public static extern IntPtr SetParent(IntPt r hWndChild, IntPtr
hWndNewParent);
[DllImport("user 32.dll")]
public static extern IntPtr FindWindow(stri ng lpClassName, string
lpWindowName);
[DllImport("user 32.dll")]
public static extern IntPtr GetWindow(IntPt r hwnd, int wCmd);
[DllImport("user 32.dll")]
public static extern int GetWindowText(I ntPtr hwnd, string
lpString, int cch);
[DllImport("user 32.dll")]
public static extern long GetWindowThread ProcessId(IntPt r hwnd,
long lpdwProcessId);
[DllImport("user 32.dll")]
public static extern bool LockWindowUpdat e(IntPtr hwndLock);
[DllImport("user 32.dll")]
public static extern IntPtr GetDesktopWindo w();
[DllImport("user 32.dll")]
public static extern bool DestroyWindow(I ntPtr hwnd);
[DllImport("user 32.dll", EntryPoint = "SetFocus")]
public static extern IntPtr ApiSetFocus(Int Ptr hwnd);
[DllImport("kern el32.dll")]
public static extern bool TerminateProces s(IntPtr hProcess, int
uExitCode);
[DllImport("kern el32.dll")]
public static extern IntPtr GetCurrentProce ss();
#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.ShowDia log(this) == DialogResult.OK )
{
string appCommand = ofdApp.FileName ;
m_process = new System.Diagnost ics.Process();
m_process.Start Info = new
System.Diagnost ics.ProcessStar tInfo(appComman d);
Program.LockWin dowUpdate(Progr am.GetDesktopWi ndow());
if (m_process.Star t())
{
Program.SetPare nt(m_process.Ha ndle, this.Handle);
}
Program.LockWin dowUpdate(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!
Comment