SCCManager/Remontor/Connector/Connect.cs

93 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Remontor.Connector
{
internal class Connect
{
private const int SWP_NOOWNERZORDER = 0x200;
private const int SWP_NOREDRAW = 0x8;
private const int SWP_NOZORDER = 0x4;
private const int SWP_SHOWWINDOW = 0x0040;
private const int WS_EX_MDICHILD = 0x40;
private const int SWP_FRAMECHANGED = 0x20;
private const int SWP_NOACTIVATE = 0x10;
private const int SWP_ASYNCWINDOWPOS = 0x4000;
private const int SWP_NOMOVE = 0x2;
private const int SWP_NOSIZE = 0x1;
private const int GWL_STYLE = (-16);
private const int WS_VISIBLE = 0x10000000;
private const int WM_CLOSE = 0x10;
private const int WS_CHILD = 0x40000000;
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
static extern bool MoveWindow(IntPtr Handle, int x, int y, int w, int h, bool repaint);
private Process Proc;
private bool Active = false;
private IComp Comp;
private string Login = "";
public delegate void UpdateConnect();
public event UpdateConnect Update;
public Connect(IComp comp)
{
Comp = comp;
}
public Connect(IComp comp, string login)
{
this.Comp = comp;
this.Login = login;
}
public void ConnectSCCM(Control panel)
{
Proc = Process.Start("notepad");
//Thread.Sleep(500); // Allow the process to open it's window
Proc.WaitForInputIdle();
SetParent(Proc.MainWindowHandle, panel.Handle);
SetWindowLong(Proc.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
MoveWindow(Proc.MainWindowHandle, panel.Bounds.X, panel.Bounds.Y, panel.Bounds.Width, panel.Bounds.Height, true);
}
public void Activ(bool act)
{
this.Active = act;
Update();
}
public bool ActiveOn
{
get { return this.Active; }
}
public IComp GetComp
{
get { return Comp; }
}
public string toString()
{
if (Login == "")
{
return Comp.GetNetNameStr();
}
return Login + "(" + Comp.GetNetNameStr() + ")";
}
}
}