From c2e8df0c0933c70f40de2eaeb9baf5203d4fc9d8 Mon Sep 17 00:00:00 2001 From: Nicola Carminati Date: Fri, 17 May 2019 14:27:39 +0200 Subject: [PATCH] Fix NC Window behaviour --- Client/View/MainForm.cs | 3 ++- Client/View/NcWindow.cs | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Client/View/MainForm.cs b/Client/View/MainForm.cs index 5b599713..97257570 100644 --- a/Client/View/MainForm.cs +++ b/Client/View/MainForm.cs @@ -123,8 +123,9 @@ namespace Active_Client.View NcWindow.ShowTaskBar(); NcWindow.MinimizeNcWindow(); + if (Config.VendorHmiConfig.Type == 3) + NcWindow.HideNcWindow(); NcWindow.MinimizeProdWindow(); - HideAUXWindow(); } else { diff --git a/Client/View/NcWindow.cs b/Client/View/NcWindow.cs index 168f9db4..ba90ea4b 100644 --- a/Client/View/NcWindow.cs +++ b/Client/View/NcWindow.cs @@ -991,8 +991,10 @@ namespace Active_Client.View //if it has the border and a title execute focus if (ActiveWindowNCWindowStyle != 0 && ActiveWindowNCWindowBorder == WS_BORDER && ReadWindowTitle(hwnd) != "") { - if (eventType == EVENT_OBJECT_CREATE && state == NcState.SHOW) + if (eventType == EVENT_OBJECT_CREATE) + { SetForegroundWindow(ncprocess.MainWindowHandle); + } else if (eventType == EVENT_OBJECT_DESTROY) SetWindowPos(MainViewHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW); } @@ -1010,7 +1012,6 @@ namespace Active_Client.View //Read the actual ID of the Process GetWindowThreadProcessId(hwnd, out ActualPID); - Console.WriteLine(ReadWindowTitle(hwnd)); //Delete the TOPMOST Style of the Window if (NcProcessPID != 0 && ActualPID == NcProcessPID) @@ -1025,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(hwnd, 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); } } @@ -1035,10 +1036,6 @@ namespace Active_Client.View { if (!IsIconic(MainViewHandle)) { - //Hide the TaskBar - if (Environment.OSVersion.Version.Major < 10) - HideTaskBar(); - //Show Virtual keyboard if (Config.ClientConfig.ShowVirtualKeyboard && Environment.OSVersion.Version.Major < 10) reOpenVirtualKeyboard(); @@ -1051,9 +1048,6 @@ namespace Active_Client.View if (Environment.OSVersion.Version.Major < 10) HideTaskBar(); - //if (LastHookedPID != MainProcessPID && LastHookedPID != NcProcessPID && LastHookedPID != ProdProcessPID) - //SetForegroundWindow(MainViewHandle); - } //If the PID is OTHER Process else @@ -1404,11 +1398,21 @@ namespace Active_Client.View //NC Following Method public static void FollowNcBehaviour() - { + { + uint process = 0; try { while (true) - { + { + + GetWindowThreadProcessId(GetForegroundWindow(), out process); + if (state != NcState.SHOW && state != NcState.SHOWPROD && (process == NcProcessPID || process == ProdProcessPID)) + mainFrm.HideAUXWindow(); + else if (state == NcState.SHOWPROD && process == NcProcessPID && prodwindowstarted) + mainFrm.ShowProdWindow(); + else if (state == NcState.SHOW && process == ProdProcessPID && windowstarted) + mainFrm.ShowNCWindow(); + if (Process.GetProcessesByName(processname).Length == 0) { //Un-parent the window