2022-10-29 00:23:06 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
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 { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-07 22:29:11 +01:00
|
|
|
|
public static void DisableMaximizeButton(this Window window)
|
2022-10-30 15:18:51 +01:00
|
|
|
|
{
|
|
|
|
|
if (!ReferenceEquals(window, null))
|
|
|
|
|
{
|
|
|
|
|
const int GWL_STYLE = -16;
|
2022-11-07 22:29:11 +01:00
|
|
|
|
const uint WS_MAXIMIZEBOX = 0x10000;
|
2022-10-30 15:18:51 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
WindowInteropHelper interopHelper = new WindowInteropHelper(window);
|
|
|
|
|
uint value = NativeMethods.GetWindowLong(interopHelper.Handle, GWL_STYLE);
|
2022-11-07 22:29:11 +01:00
|
|
|
|
if ((value & WS_MAXIMIZEBOX) != 0U)
|
2022-10-30 15:18:51 +01:00
|
|
|
|
{
|
2022-11-07 22:29:11 +01:00
|
|
|
|
NativeMethods.SetWindowLong(interopHelper.Handle, GWL_STYLE, value & (~WS_MAXIMIZEBOX));
|
2022-10-30 15:18:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-29 00:23:06 +02:00
|
|
|
|
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);
|
2022-10-30 15:18:51 +01:00
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
|
|
|
public static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
|
|
|
public static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
|
2022-10-29 00:23:06 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|