First Commit (not clean, only for test)

This commit is contained in:
Nicola Carminati
2019-05-20 11:38:54 +02:00
parent c2e8df0c09
commit 931f595f3e
2 changed files with 69 additions and 115 deletions
+56 -63
View File
@@ -123,26 +123,16 @@ namespace Active_Client.View
NcWindow.ShowTaskBar();
NcWindow.MinimizeNcWindow();
if (Config.VendorHmiConfig.Type == 3)
NcWindow.HideNcWindow();
//if (Config.VendorHmiConfig.Type == 3)
// NcWindow.HideNcWindow();
NcWindow.MinimizeProdWindow();
}
else
{
NcWindow.ShowNcWindow();
NcWindow.ShowProdWindow();
//NcWindow.ShowProdWindow();
if (NcWindow.State == NcState.SHOW)
{
ShowNCWindow();
}
else if(NcWindow.State == NcState.SHOWPROD)
{
ShowProdWindow();
}
else
HideAUXWindow();
}
@@ -600,36 +590,37 @@ namespace Active_Client.View
if (!Config.VendorHmiConfig.Enabled)
return;
NcWindow.ShowNcWindow();
//Invoke method if is needed or call the method in STD mode
if (!IsDisposed)
{
if (InvokeRequired)
Invoke((MethodInvoker)delegate ()
{
if (NcFrm.Owner == null)
{
Owner = null;
NcFrm.Owner = this;
if (ProdFrm != null)
ProdFrm.Owner = null;
}
NcFrm.TopMost = true;
NcFrm.TopMost = false;
});
//if (!IsDisposed)
//{
// if (InvokeRequired)
// Invoke((MethodInvoker)delegate ()
// {
// if (NcFrm.Owner == null)
// {
// Owner = null;
// NcFrm.Owner = this;
// if (ProdFrm != null)
// ProdFrm.Owner = null;
// }
// NcFrm.TopMost = true;
// NcFrm.TopMost = false;
// });
else
{
if (NcFrm.Owner == null)
{
Owner = null;
NcFrm.Owner = this;
if (ProdFrm != null)
ProdFrm.Owner = null;
}
NcFrm.TopMost = true;
NcFrm.TopMost = false;
}
}
// else
// {
// if (NcFrm.Owner == null)
// {
// Owner = null;
// NcFrm.Owner = this;
// if (ProdFrm != null)
// ProdFrm.Owner = null;
// }
// NcFrm.TopMost = true;
// NcFrm.TopMost = false;
// }
//}
}
//Show NC Method
@@ -679,30 +670,32 @@ namespace Active_Client.View
if ((!Config.VendorHmiConfig.Enabled && !Config.ProdSoftwareConfig.Enabled) || (NcFrm==null && ProdFrm == null))
return;
//NcWindow.HideNcWindow();
NcWindow.HideNcWindow();
//Invoke method if is needed or call the method in STD mode
if (!IsDisposed)
{
if (InvokeRequired)
Invoke((MethodInvoker)delegate ()
{
if (NcFrm != null && NcFrm.Owner != null)
NcFrm.Owner = null;
if (ProdFrm != null && ProdFrm.Owner != null)
ProdFrm.Owner = null;
TopMost = true;
TopMost = false;
});
//if (!IsDisposed)
//{
// if (InvokeRequired)
// Invoke((MethodInvoker)delegate ()
// {
// if (NcFrm != null && NcFrm.Owner != null)
// NcFrm.Owner = null;
// if (ProdFrm != null && ProdFrm.Owner != null)
// ProdFrm.Owner = null;
// TopMost = true;
// TopMost = false;
// });
else
{
if (NcFrm != null && NcFrm.Owner != null)
NcFrm.Owner = null;
if (ProdFrm != null && ProdFrm.Owner != null)
ProdFrm.Owner = null;
TopMost = true;
TopMost = false;
}
}
// else
// {
// if (NcFrm != null && NcFrm.Owner != null)
// NcFrm.Owner = null;
// if (ProdFrm != null && ProdFrm.Owner != null)
// ProdFrm.Owner = null;
// TopMost = true;
// TopMost = false;
// }
//}
}
+13 -52
View File
@@ -479,8 +479,8 @@ namespace Active_Client.View
//Hide Nc Window
public static void HideNcWindow()
{
if (windowstarted)
ShowWindow(ncprocess.MainWindowHandle, WS_HIDE);
if (windowstarted)
ResizeAndMoveNcWindow(ncWindowX, ncWindowY, 0, 0);
}
//Hide Prod Window
@@ -604,11 +604,11 @@ namespace Active_Client.View
//Set the parent of the window
if (windowstarted)
SetParent(ncprocess.MainWindowHandle, NcHandle);
SetParent(ncprocess.MainWindowHandle, MainViewHandle);
//Set the parent of the window
if (prodwindowstarted)
SetParent(prodprocess.MainWindowHandle, ProdHandle);
SetParent(prodprocess.MainWindowHandle, MainViewHandle);
//Get the Process-Id
GetWindowThreadProcessId(MainViewHandle, out MainProcessPID);
@@ -1026,7 +1026,7 @@ namespace Active_Client.View
//if it has the border and a title execute focus
if (ActiveNCWindowStyle != 0 && ActiveNCWindowBorder == WS_BORDER && ReadWindowTitle(hwnd) != "" && hwnd != ncprocess.MainWindowHandle)
{
SetWindowPos(ncprocess.MainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
//SetWindowPos(ncprocess.MainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
}
}
@@ -1117,50 +1117,7 @@ namespace Active_Client.View
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region PRIVATE_CUSTOM_METHODS
//Resize out of Bound window
private static void ResizeOutofBoundWindow(IntPtr ParentHandle, IntPtr WindowHandle)
{
RECT MainRct;
RECT ParentRct;
int width;
int height;
int width2;
int height2;
int newX;
int newY;
bool move = false;
bool resize = false;
if (GetWindowRect(WindowHandle, out MainRct) && GetWindowRect(ParentHandle, out ParentRct))
{
//Setup resize and move variables
width = (MainRct.Right - MainRct.Left + 1);
height = (MainRct.Bottom - MainRct.Top + 1);
width2 = (ParentRct.Right - ParentRct.Left + 1);
height2 = (ParentRct.Bottom - ParentRct.Top + 1);
newX = width2 / 2 - width / 2 + ParentRct.Left;
newY = height2 / 2 - height / 2 + ParentRct.Top;
//Check if i need to resize
if (width > width2 || height > height2)
resize = true;
//Check if i need to move
if (MainRct.Left < ParentRct.Left || MainRct.Top < ParentRct.Top || MainRct.Right > ParentRct.Right || MainRct.Bottom > ParentRct.Bottom)
move = true;
//Move or Resize the Window
if (move & !resize)
MoveWindow(WindowHandle, newX, newY, width, height, true);
else if (resize)
MoveWindow(WindowHandle, ParentRct.Left, ParentRct.Top, LastWidth, LastHeight, true);
}
}
//Read Window Title
private static string ReadWindowTitle(IntPtr hwnd)
{
int length = GetWindowTextLength(hwnd);
@@ -1177,11 +1134,11 @@ namespace Active_Client.View
LastY = Y;
LastWidth = width;
LastHeight = height;
bool repaint = Config.VendorHmiConfig.Type == 1;
//Win32 Method
if (ncprocess != null && windowstarted)
{
MoveWindow(ncprocess.MainWindowHandle, LastX, LastY, LastWidth, LastHeight, true);
MoveWindow(ncprocess.MainWindowHandle, LastX, LastY, LastWidth, LastHeight, repaint);
}
}
@@ -1401,7 +1358,9 @@ namespace Active_Client.View
{
uint process = 0;
try
{
{
Process[] pr = Process.GetProcessesByName(processname);
while (true)
{
@@ -1413,7 +1372,9 @@ namespace Active_Client.View
else if (state == NcState.SHOW && process == ProdProcessPID && windowstarted)
mainFrm.ShowNCWindow();
if (Process.GetProcessesByName(processname).Length == 0)
pr = Process.GetProcessesByName(processname);
if (pr.Length == 0)
{
//Un-parent the window
if (ncprocess.MainWindowHandle != IntPtr.Zero)