From 4da5466de957e001c1a94d4824699e26b65340f6 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Tue, 5 Nov 2019 17:32:14 +0100 Subject: [PATCH] FrmScreenAutomation: Only top level while running. --- VAR.ScreenAutomation/Code/WindowHandling.cs | 12 ++++++++++-- VAR.ScreenAutomation/FrmScreenAutomation.cs | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/VAR.ScreenAutomation/Code/WindowHandling.cs b/VAR.ScreenAutomation/Code/WindowHandling.cs index 33733e5..bf5364a 100644 --- a/VAR.ScreenAutomation/Code/WindowHandling.cs +++ b/VAR.ScreenAutomation/Code/WindowHandling.cs @@ -8,6 +8,7 @@ namespace VAR.ScreenAutomation.Code public class WindowHandling { private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); + private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); private const UInt32 SWP_NOSIZE = 0x0001; private const UInt32 SWP_NOMOVE = 0x0002; private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE; @@ -16,9 +17,16 @@ namespace VAR.ScreenAutomation.Code [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); - public static void WindowSetTopLevel(Form form) + public static void WindowSetTopLevel(Form form, bool top = true) { - SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); + if (top) + { + SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); + } + else + { + SetWindowPos(form.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); + } } public static bool ApplicationIsActivated() diff --git a/VAR.ScreenAutomation/FrmScreenAutomation.cs b/VAR.ScreenAutomation/FrmScreenAutomation.cs index eb2585b..9a78b5a 100644 --- a/VAR.ScreenAutomation/FrmScreenAutomation.cs +++ b/VAR.ScreenAutomation/FrmScreenAutomation.cs @@ -59,7 +59,6 @@ namespace VAR.ScreenAutomation timTicker.Enabled = true; timTicker.Start(); - WindowHandling.WindowSetTopLevel(this); } private void FrmScreenAutomation_FormClosing(object sender, FormClosingEventArgs e) @@ -118,6 +117,7 @@ namespace VAR.ScreenAutomation { if (_running) { return; } _running = true; + WindowHandling.WindowSetTopLevel(this); btnStartEnd.Text = "End"; _automationBot = AutomationBotFactory.CreateFromName((string)ddlAutomationBot.SelectedItem); _automationBot?.Init(ctrOutput); @@ -131,6 +131,7 @@ namespace VAR.ScreenAutomation if (_running == false) { return; } _running = false; btnStartEnd.Text = "Start"; + WindowHandling.WindowSetTopLevel(this, false); } private void DdlAutomationBot_SelectedIndexChanged(object sender, EventArgs e)