140 lines
3.9 KiB
C#
140 lines
3.9 KiB
C#
using Remontor.Setting;
|
||
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);
|
||
|
||
|
||
|
||
private IModeMon ModeMonitor;
|
||
private Process Proc;
|
||
private bool Active = false;
|
||
private IComp Comp;
|
||
private string Login = "";
|
||
public delegate void UpdateConnect();
|
||
public event UpdateConnect Update;
|
||
public Control View;
|
||
public Connect(IComp comp)
|
||
{
|
||
Comp = comp;
|
||
|
||
}
|
||
|
||
public Connect(IComp comp, string login)
|
||
{
|
||
this.Comp = comp;
|
||
this.Login = login;
|
||
}
|
||
|
||
public void ConnectSCCM(Control panel)
|
||
{
|
||
try {
|
||
View = new Panel();
|
||
View.Dock = DockStyle.Fill;
|
||
panel.Controls.Add(View);
|
||
ModeMonitor = new OneMon();
|
||
Proc = Process.Start(SGlobalSetting.settingApp.pathApp, Comp.GetNetNameStr());
|
||
//Proc = Process.Start(SGlobalSetting.settingApp.pathApp);
|
||
//Thread.Sleep(500); // Allow the process to open it's window
|
||
Proc.WaitForInputIdle();
|
||
SetParent(Proc.MainWindowHandle, View.Handle);
|
||
SetWindowLong(Proc.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
|
||
ModeMonitor.Resize(Proc, View);
|
||
}
|
||
catch (Exception) {
|
||
MessageBox.Show("Не верно заданно приложение для подключения.");
|
||
ModeMonitor = new OffMon();
|
||
SConnector.Panel.Controls.Remove(View);
|
||
return;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
public void Activ(bool act)
|
||
{
|
||
this.Active = act;
|
||
View.Visible = act;
|
||
if(act)Resize();
|
||
ModeMonitor.Resize(Proc, View);
|
||
Update();
|
||
}
|
||
|
||
public bool ActiveOn
|
||
{
|
||
get { return this.Active; }
|
||
|
||
}
|
||
|
||
public void Resize()
|
||
{
|
||
ModeMonitor.Resize(Proc, View);
|
||
}
|
||
|
||
public IModeMon GetModeMon()
|
||
{
|
||
return ModeMonitor;
|
||
}
|
||
|
||
public IModeMon SetModeMon(IModeMon Mode)
|
||
|
||
{
|
||
|
||
ModeMonitor = ModeMonitor.Change(Mode);
|
||
ModeMonitor.Resize(Proc, View);
|
||
return ModeMonitor;
|
||
}
|
||
|
||
public IComp GetComp
|
||
{
|
||
get { return Comp; }
|
||
}
|
||
public string toString()
|
||
{
|
||
if (Login == "")
|
||
{
|
||
return Comp.GetNetNameStr();
|
||
}
|
||
return Login + "(" + Comp.GetNetNameStr() + ")";
|
||
}
|
||
|
||
public void Delete()
|
||
{
|
||
if (Proc != null) Proc.CloseMainWindow();
|
||
ModeMonitor = new OffMon();
|
||
SConnector.Panel.Controls.Remove(View);
|
||
if (Proc != null) Proc.Close();
|
||
}
|
||
}
|
||
}
|