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
46
47
48
49
50
51
52
|
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Diagnostics;
namespace Tools{
class CmdDocking {
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr
FindWindow([MarshalAs(UnmanagedType.LPTStr)] string lpClassName,
[MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
int Y, int cx, int cy, uint uFlags);
public CmdDocking(){
StartConsole();
}
private const String ClassName = "ConsoleWindowClass";
/// <summary>
/// Die System Console CMD.EXE starten
/// </summary>
private void StartConsole() {
Process process = new Process();
process.StartInfo = new ProcessStartInfo(string.Format(@"{0}\cmd.exe",Environment.GetFolderPath(Environment.SpecialFolder.System)));
process.Start();
}
/// <summary>
/// Console in eigene Form einbinden
/// </summary>
/// <param name="formToDock">Form in die, die Console eingebunden werden soll</param>
/// <param name="posX">Position X des Consolen Fensters</param>
/// <param name="posY">Position Y des Consolen Fensters</param>
/// <param name="width">Breite des consolen Fensters</param>
/// <param name="hight">Höhe des consolen Fensters</param>
public void DockConsole(Form formToDock, int posX, int posY, int width, int hight) {
SetWindowPos(GetHwnd(), IntPtr.Zero, posX, posY, width, hight, 0);
SetParent(GetHwnd(), formToDock.Handle);
}
private IntPtr GetHwnd() {
return FindWindow(ClassName, null);
}
}
}
|