FrmScreenAutomation: Only top level while running.

This commit is contained in:
2019-11-05 17:32:14 +01:00
parent 2f8f4492ea
commit 4da5466de9
2 changed files with 12 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ namespace VAR.ScreenAutomation.Code
public class WindowHandling public class WindowHandling
{ {
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); 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_NOSIZE = 0x0001;
private const UInt32 SWP_NOMOVE = 0x0002; private const UInt32 SWP_NOMOVE = 0x0002;
private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE; private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
@@ -16,10 +17,17 @@ namespace VAR.ScreenAutomation.Code
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); 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)
{
if (top)
{ {
SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); 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() public static bool ApplicationIsActivated()
{ {

View File

@@ -59,7 +59,6 @@ namespace VAR.ScreenAutomation
timTicker.Enabled = true; timTicker.Enabled = true;
timTicker.Start(); timTicker.Start();
WindowHandling.WindowSetTopLevel(this);
} }
private void FrmScreenAutomation_FormClosing(object sender, FormClosingEventArgs e) private void FrmScreenAutomation_FormClosing(object sender, FormClosingEventArgs e)
@@ -118,6 +117,7 @@ namespace VAR.ScreenAutomation
{ {
if (_running) { return; } if (_running) { return; }
_running = true; _running = true;
WindowHandling.WindowSetTopLevel(this);
btnStartEnd.Text = "End"; btnStartEnd.Text = "End";
_automationBot = AutomationBotFactory.CreateFromName((string)ddlAutomationBot.SelectedItem); _automationBot = AutomationBotFactory.CreateFromName((string)ddlAutomationBot.SelectedItem);
_automationBot?.Init(ctrOutput); _automationBot?.Init(ctrOutput);
@@ -131,6 +131,7 @@ namespace VAR.ScreenAutomation
if (_running == false) { return; } if (_running == false) { return; }
_running = false; _running = false;
btnStartEnd.Text = "Start"; btnStartEnd.Text = "Start";
WindowHandling.WindowSetTopLevel(this, false);
} }
private void DdlAutomationBot_SelectedIndexChanged(object sender, EventArgs e) private void DdlAutomationBot_SelectedIndexChanged(object sender, EventArgs e)