55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using VDash.Utilities;
|
|
|
|
namespace VDash.Overlay.Actions
|
|
{
|
|
public class BringWindowToFrontAction : IOverlayAction
|
|
{
|
|
/// <summary>
|
|
/// Unminimize the window if it's minimized.
|
|
/// </summary>
|
|
public bool UnminimizeIfMinimized { get; set; }
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
public BringWindowToFrontAction(bool unminimizeIfMinimized)
|
|
{
|
|
UnminimizeIfMinimized = unminimizeIfMinimized;
|
|
}
|
|
|
|
public void PreformAction(IOverlay intOverlay)
|
|
{
|
|
if (!Enabled) { return; }
|
|
if (!intOverlay.GetType().IsAssignableFrom(typeof(WindowOverlay)))
|
|
{
|
|
Console.WriteLine("This action cannot be performed on a non-WindowOverlay overlay.");
|
|
return;
|
|
}
|
|
|
|
WindowOverlay overlay = (WindowOverlay)intOverlay;
|
|
IntPtr handle = overlay.Config.Selector.GetWindowHandle();
|
|
PreformAction(handle);
|
|
}
|
|
|
|
public void PreformAction(IntPtr handle)
|
|
{
|
|
//Make sure window isn't minimized
|
|
User32.WINDOWPLACEMENT placement = new User32.WINDOWPLACEMENT();
|
|
placement.Length = Marshal.SizeOf(placement);
|
|
User32.GetWindowPlacement(handle, ref placement);
|
|
|
|
if (placement.ShowCmd == User32.ShowWindowCommands.ShowMinimized)
|
|
{
|
|
User32.ShowWindow(handle, User32.ShowWindowCommands.Normal);
|
|
}
|
|
|
|
User32.SetForegroundWindow(handle);
|
|
}
|
|
}
|
|
}
|