Explicitly bring application window to front on startup.

This commit is contained in:
LoRd_MuldeR 2022-10-29 00:23:06 +02:00
parent b00f31bd72
commit 7996869e3c
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
5 changed files with 50 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -26,7 +26,9 @@ SubCaption 4 " "
Sleep 333
!macroend
Section ""
Section
BringToFront # Just to be sure!
!insertmacro PrintStatusMessage "Detecting operating system, please wait..."
${IfNot} ${AtLeastBuild} 7601
MessageBox MB_ICONSTOP|MB_TOPMOST "This application runs on Windows 7 (SP1) or later!"
@ -40,7 +42,7 @@ Section ""
ReadRegDWORD $0 HKLM 'SOFTWARE\WOW6432Node\Microsoft\NET Framework Setup\NDP\v4\Full' 'Release'
${IfNot} ${Errors}
DetailPrint "Installed release: $0"
${IfThen} $0 >= 528040 ${|} Goto launch_application ${|}
${IfThen} $0 >= 461808 ${|} Goto launch_application ${|}
${Else}
DetailPrint ".NET Framework not found!"
${Endif}

View File

@ -96,6 +96,7 @@
<Compile Include="Utilities\FontSizeConverter.cs" />
<Compile Include="Utilities\ProcessRunner.cs" />
<Compile Include="Utilities\VersionInfo.cs" />
<Compile Include="Utilities\WindowHelper.cs" />
<Page Include="Controls\Hyperlink.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -3,6 +3,7 @@
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
using Microsoft.Win32;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
@ -19,7 +20,6 @@ using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Shell;
using System.Windows.Threading;
using Microsoft.Win32;
using com.muldersoft.slunkcrypt.gui.ctrls;
using com.muldersoft.slunkcrypt.gui.process;
@ -114,6 +114,7 @@ namespace com.muldersoft.slunkcrypt.gui
TabControl.MinHeight = TabControl.MaxHeight = TabControl.ActualHeight;
MinWidth = MaxWidth = ActualWidth;
MinHeight = MaxHeight = ActualHeight;
this.BringWindowToTop();
}
private void Button_Encrypt_InputFile_Click(object sender, RoutedEventArgs e)

View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
namespace com.muldersoft.slunkcrypt.gui.utils
{
public static class WindowHelper
{
private static readonly IEnumerable<bool> enableTopmost = Array.AsReadOnly(new bool[] { true, false });
public static void BringWindowToTop(this Window window)
{
if (!ReferenceEquals(window, null))
{
try
{
WindowInteropHelper interopHelper = new WindowInteropHelper(window);
NativeMethods.BringWindowToTop(interopHelper.Handle);
if (!NativeMethods.SetForegroundWindow(interopHelper.Handle))
{
foreach (bool flag in enableTopmost)
{
window.Topmost = flag;
}
}
}
catch { }
}
}
private static class NativeMethods
{
[DllImport("user32.dll", SetLastError = true)]
public static extern bool BringWindowToTop(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
}
}