VRDash/VDash/Overlay/Actions/ResizeWindowAction.cs

48 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDash.Utilities;
namespace VDash.Overlay.Actions
{
public class ResizeWindowAction : IOverlayAction
{
public int NewWidth { get; set; }
public int NewHeight { get; set; }
public bool Enabled { get; set; }
public ResizeWindowAction(int newWidth, int newHeight)
{
NewWidth = newWidth;
NewHeight = newHeight;
}
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.Selector.GetWindowHandle();
PreformAction(handle);
}
public void PreformAction(IntPtr handle)
{
//Retain old rect
User32.Rect rect = new User32.Rect();
User32.GetWindowRect(handle, ref rect);
User32.SetWindowPos(handle, IntPtr.Zero, rect.left, rect.bottom, NewWidth, NewHeight, User32.SetWindowPosFlags.DoNotActivate |
User32.SetWindowPosFlags.IgnoreMove | User32.SetWindowPosFlags.IgnoreZOrder |
User32.SetWindowPosFlags.DoNotChangeOwnerZOrder);
}
}
}