SCCManager/Remontor/Connector/Connect.cs

141 lines
3.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 (Comp.GetName() == null)
{
return Comp.GetNetNameStr();
}
return Comp.GetName() + "(" + Comp.GetNetNameStr() + ")";
}
public void Delete()
{
if (Proc != null) Proc.CloseMainWindow();
ModeMonitor = new OffMon();
SConnector.Panel.Controls.Remove(View);
if (Proc != null) Proc.Close();
}
}
}