1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| [System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool MoveWindow(IntPtr Handle, int x, int y, int w, int h, bool repaint);
static readonly int GWL_STYLE = -16;
static readonly int WS_VISIBLE = 0x10000000;
private void testToolStripMenuItem_Click(object sender, EventArgs e)
{
Panel pnl = new Panel();
pnl.Name = "panel1";
pnl.BackColor = Color.Pink;
pnl.Dock = DockStyle.Fill;
pnl.Visible = true;
this.Controls.Add(pnl);
try
{
Process p = Process.Start("test.exe");
Thread.Sleep(100);
p.WaitForInputIdle();
try
{
foreach (Control ctrl in Controls)
{
if (ctrl.Name == "panel1")
{
SetParent(p.MainWindowHandle, ctrl.Handle);
}
}
}
finally
{
//
}
SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
MoveWindow(p.MainWindowHandle, 0, 0, this.Width, this.Height, true);
}
finally
{
//
}
} |
Partager