110,567
社区成员
发帖
与我相关
我的任务
分享
[DllImport("user32", EntryPoint = "SetParent", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32", EntryPoint = "FindWindowA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessageA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);
[DllImport("shell32.dll", EntryPoint = "ShellExecuteA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int ShellExecute(int hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
private const int WM_SYSCOMMAND = 0x112;
private const int SC_MAXIMIZE = 0xF030;
private const int SC_MINIMIZE = 0xF020;
private const int SC_RESTORE = 0xF120;
public const int SW_HIDE = 0;
public const int SW_SHOW = 5;
[DllImport("user32.dll ", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int ShowWindow(int hwnd, int nCmdShow);
private void button1_Click(object sender, EventArgs e)
{
ShellExecute(this.panel1.Handle.ToInt32(), "open", @"D:\MY Program\CtrlDemo\CtrlDemo\bin\Debug\CtrlDemo.exe", null, ".", SW_HIDE); // 让CtrlDemo.exe运行在PANEL里面
IntPtr h = FindWindow(null, "c:\\windows\\system32\\cmd.exe ");
SetParent(h, this.panel1.Handle); //嵌套到panel1内
SendMessage(h.ToInt32(), WM_SYSCOMMAND, SC_MAXIMIZE, 0);
ShowWindow(h.ToInt32(), SW_SHOW);
}
[DllImport("user32", EntryPoint = "SetParent", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32", EntryPoint = "FindWindowA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessageA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);
[DllImport("shell32.dll", EntryPoint = "ShellExecuteA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int ShellExecute(int hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
private const int WM_SYSCOMMAND = 0x112;
private const int SC_MAXIMIZE = 0xF030;
private const int SC_MINIMIZE = 0xF020;
private const int SC_RESTORE = 0xF120;
public const int SW_HIDE = 0;
public const int SW_SHOW = 5;
[DllImport("user32.dll ", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int ShowWindow(int hwnd, int nCmdShow);
private void button1_Click(object sender, EventArgs e)
{
ShellExecute(this.panel1.Handle.ToInt32(), "open", @"D:\MY Program\CtrlDemo\CtrlDemo\bin\Debug\CtrlDemo.exe", null, ".", SW_HIDE); // 让CtrlDemo.exe运行在PANEL里面
IntPtr h = FindWindow(null, "c:\\windows\\system32\\cmd.exe ");
//关键在这里
Form frm = Form.FromHandle(h);
//使你的Form可以嵌入别的容器
frm.TopLevel = false;
SetParent(h, this.panel1.Handle); //嵌套到panel1内
SendMessage(h.ToInt32(), WM_SYSCOMMAND, SC_MAXIMIZE, 0);
ShowWindow(h.ToInt32(), SW_SHOW);
}