Switch to .NET Core
This commit is contained in:
parent
033d0e4cc6
commit
d5e5736d51
|
@ -0,0 +1,2 @@
|
||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
|
@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.29230.47
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resizor", "Resizor\Resizor.csproj", "{EED8B478-D539-41D2-9A39-8349099B298A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resizor", "Resizor\Resizor.csproj", "{EED8B478-D539-41D2-9A39-8349099B298A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "W32", "..\CC-Functions\W32\W32.csproj", "{23DE4AE0-5075-4CCC-8440-4D131CA0FBBA}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -17,10 +15,6 @@ Global
|
||||||
{EED8B478-D539-41D2-9A39-8349099B298A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{EED8B478-D539-41D2-9A39-8349099B298A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{EED8B478-D539-41D2-9A39-8349099B298A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{EED8B478-D539-41D2-9A39-8349099B298A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{EED8B478-D539-41D2-9A39-8349099B298A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{EED8B478-D539-41D2-9A39-8349099B298A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{23DE4AE0-5075-4CCC-8440-4D131CA0FBBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{23DE4AE0-5075-4CCC-8440-4D131CA0FBBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{23DE4AE0-5075-4CCC-8440-4D131CA0FBBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{23DE4AE0-5075-4CCC-8440-4D131CA0FBBA}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
namespace Resizor
|
namespace Resizor
|
||||||
{
|
{
|
||||||
partial class immResize
|
partial class ImmResize
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
this.MinimizeBox = false;
|
this.MinimizeBox = false;
|
||||||
this.Name = "immResize";
|
this.Name = "ImmResize";
|
||||||
this.Opacity = 0.5D;
|
this.Opacity = 0.5D;
|
||||||
this.ShowIcon = false;
|
this.ShowIcon = false;
|
||||||
this.ShowInTaskbar = false;
|
this.ShowInTaskbar = false;
|
||||||
|
|
|
@ -1,47 +1,49 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using CC_Functions.W32;
|
using CC_Functions.W32;
|
||||||
|
using CC_Functions.W32.Hooks;
|
||||||
using Resizor.Properties;
|
using Resizor.Properties;
|
||||||
|
|
||||||
namespace Resizor
|
namespace Resizor
|
||||||
{
|
{
|
||||||
public partial class immResize : Form
|
public partial class ImmResize : Form
|
||||||
{
|
{
|
||||||
bool down;
|
private readonly Wnd32 _window;
|
||||||
Point startP;
|
private bool _down;
|
||||||
Wnd32 window;
|
private Rectangle _prevR;
|
||||||
Rectangle prevR;
|
private Rectangle _screen = Screen.PrimaryScreen.WorkingArea;
|
||||||
Rectangle screen = Screen.PrimaryScreen.WorkingArea;
|
private Point _startP;
|
||||||
public immResize()
|
|
||||||
|
public ImmResize()
|
||||||
{
|
{
|
||||||
prevR = new Rectangle();
|
_prevR = new Rectangle();
|
||||||
window = Wnd32.foreground();
|
_window = Wnd32.Foreground;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Program.kh.OnKeyPress += onKeyDown;
|
Program.Kh.OnKeyPress += OnKeyDown;
|
||||||
Rectangle tmp = window.position;
|
Rectangle tmp = _window.Position;
|
||||||
forcePos.Location = new Point((tmp.X + (tmp.Width / 2)) - (forcePos.Width / 2), tmp.Y);
|
forcePos.Location = new Point((tmp.X + (tmp.Width / 2)) - (forcePos.Width / 2), tmp.Y);
|
||||||
forcePos.Checked = Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length > 0;
|
forcePos.Checked = Program.Ctx.WindowSizeSetters.Where(s => s.Window == _window).ToArray().Length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onKeyDown(KeyboardHookEventArgs _args)
|
private void OnKeyDown(KeyboardHookEventArgs args)
|
||||||
{
|
{
|
||||||
if (_args.Key == Keys.Escape)
|
if (args.Key == Keys.Escape)
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ImmResize_FormClosed(object sender, FormClosedEventArgs e) => Program.kh.OnKeyPress -= onKeyDown;
|
private void ImmResize_FormClosed(object sender, FormClosedEventArgs e) => Program.Kh.OnKeyPress -= OnKeyDown;
|
||||||
|
|
||||||
private void Form1_Load(object sender, EventArgs e)
|
private void Form1_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Wnd32 self = Wnd32.fromForm(this);
|
Wnd32 self = this.GetWnd32();
|
||||||
self.MakeOverlay();
|
self.Overlay = true;
|
||||||
if (self != window)
|
if (self != _window)
|
||||||
self.isForeground = true;
|
self.IsForeground = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_Paint(object sender, PaintEventArgs e)
|
private void Form1_Paint(object sender, PaintEventArgs e)
|
||||||
{
|
{
|
||||||
Graphics g = e.Graphics;
|
Graphics g = e.Graphics;
|
||||||
|
@ -51,69 +53,63 @@ namespace Resizor
|
||||||
g.CompositingQuality = CompositingQuality.HighSpeed;
|
g.CompositingQuality = CompositingQuality.HighSpeed;
|
||||||
g.PixelOffsetMode = PixelOffsetMode.None;
|
g.PixelOffsetMode = PixelOffsetMode.None;
|
||||||
PointF divisor = Settings.Default.ResizeDividor;
|
PointF divisor = Settings.Default.ResizeDividor;
|
||||||
Rectangle rect;
|
Rectangle rect = _down ? FRect() : CRect();
|
||||||
if (down)
|
|
||||||
rect = FRect();
|
|
||||||
else
|
|
||||||
rect = CRect();
|
|
||||||
g.FillRectangle(new SolidBrush(Color.LightBlue), rect);
|
g.FillRectangle(new SolidBrush(Color.LightBlue), rect);
|
||||||
Pen gridPen = new Pen(Color.Black, 2);
|
Pen gridPen = new Pen(Color.Black, 2);
|
||||||
PointF div = getDiv();
|
PointF div = GetDiv();
|
||||||
for (int x = 0; x < divisor.X; x++)
|
for (int x = 0; x < divisor.X; x++) g.DrawLine(gridPen, x * div.X, 0, x * div.X, _screen.Height);
|
||||||
{
|
for (int y = 0; y < divisor.Y; y++) g.DrawLine(gridPen, 0, y * div.Y, _screen.Width, y * div.Y);
|
||||||
g.DrawLine(gridPen, x * div.X, 0, x * div.X, screen.Height);
|
|
||||||
}
|
|
||||||
for (int y = 0; y < divisor.Y; y++)
|
|
||||||
{
|
|
||||||
g.DrawLine(gridPen, 0, y * div.Y, screen.Width, y * div.Y);
|
|
||||||
}
|
|
||||||
g.DrawRectangle(new Pen(Color.Blue, 2), rect);
|
g.DrawRectangle(new Pen(Color.Blue, 2), rect);
|
||||||
g.DrawRectangle(new Pen(Color.Red, 2), window.position);
|
g.DrawRectangle(new Pen(Color.Red, 2), _window.Position);
|
||||||
}
|
}
|
||||||
PointF getDiv() => new PointF(screen.Width / Settings.Default.ResizeDividor.X, screen.Height / Settings.Default.ResizeDividor.Y);
|
|
||||||
Rectangle CRect() => p2r(f2s(MousePosition, getDiv()), c2s(MousePosition, getDiv()));
|
private PointF GetDiv() => new PointF(_screen.Width / (float) Settings.Default.ResizeDividor.X,
|
||||||
Rectangle FRect()
|
_screen.Height / (float) Settings.Default.ResizeDividor.Y);
|
||||||
|
|
||||||
|
private Rectangle CRect() => P2R(F2S(MousePosition, GetDiv()), C2S(MousePosition, GetDiv()));
|
||||||
|
|
||||||
|
private Rectangle FRect()
|
||||||
{
|
{
|
||||||
Point min = f2s(new Point(Math.Min(MousePosition.X, startP.X), Math.Min(MousePosition.Y, startP.Y)), getDiv());
|
Point min = F2S(new Point(Math.Min(MousePosition.X, _startP.X), Math.Min(MousePosition.Y, _startP.Y)),
|
||||||
Point max = c2s(new Point(Math.Max(MousePosition.X, startP.X), Math.Max(MousePosition.Y, startP.Y)), getDiv());
|
GetDiv());
|
||||||
return p2r(min, max);
|
Point max = C2S(new Point(Math.Max(MousePosition.X, _startP.X), Math.Max(MousePosition.Y, _startP.Y)),
|
||||||
|
GetDiv());
|
||||||
|
return P2R(min, max);
|
||||||
}
|
}
|
||||||
Point f2s(Point p, PointF step) => new Point(f2s(p.X, step.X), f2s(p.Y, step.Y));
|
|
||||||
Point c2s(Point p, PointF step) => new Point(c2s(p.X, step.X), c2s(p.Y, step.Y));
|
private static Point F2S(Point p, PointF step) => new Point(F2S(p.X, step.X), F2S(p.Y, step.Y));
|
||||||
Rectangle p2r(Point p1, Point p2) => new Rectangle(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y), Math.Abs(p1.X - p2.X), Math.Abs(p1.Y - p2.Y));
|
private static Point C2S(Point p, PointF step) => new Point(C2S(p.X, step.X), C2S(p.Y, step.Y));
|
||||||
int f2s(int f, double step) => (int)d2f(Math.Floor(f / step) * step);
|
|
||||||
int c2s(int f, double step) => (int)d2f(Math.Ceiling(f / step) * step);
|
private static Rectangle P2R(Point p1, Point p2) => new Rectangle(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y),
|
||||||
float d2f(double f)
|
Math.Abs(p1.X - p2.X), Math.Abs(p1.Y - p2.Y));
|
||||||
|
|
||||||
|
private static int F2S(int f, double step) => (int) D2F(Math.Floor(f / step) * step);
|
||||||
|
private static int C2S(int f, double step) => (int) D2F(Math.Ceiling(f / step) * step);
|
||||||
|
|
||||||
|
private static float D2F(double f)
|
||||||
{
|
{
|
||||||
float result = (float)f;
|
float result = (float) f;
|
||||||
if (float.IsPositiveInfinity(result))
|
return float.IsPositiveInfinity(result) ? float.MaxValue :
|
||||||
return float.MaxValue;
|
float.IsNegativeInfinity(result) ? float.MinValue : result;
|
||||||
else if (float.IsNegativeInfinity(result))
|
|
||||||
return float.MinValue;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_MouseDown(object sender, MouseEventArgs e)
|
private void Form1_MouseDown(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
down = true;
|
_down = true;
|
||||||
startP = MousePosition;
|
_startP = MousePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_MouseMove(object sender, MouseEventArgs e)
|
private void Form1_MouseMove(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
Rectangle rect;
|
Rectangle rect = _down ? FRect() : CRect();
|
||||||
if (down)
|
if (_prevR != rect)
|
||||||
rect = FRect();
|
|
||||||
else
|
|
||||||
rect = CRect();
|
|
||||||
if (prevR != rect)
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
prevR = rect;
|
_prevR = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_MouseUp(object sender, MouseEventArgs e)
|
private void Form1_MouseUp(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
window.position = FRect();
|
_window.Position = FRect();
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,20 +117,16 @@ namespace Resizor
|
||||||
{
|
{
|
||||||
if (forcePos.Checked)
|
if (forcePos.Checked)
|
||||||
{
|
{
|
||||||
if (Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length == 0)
|
if (Program.Ctx.WindowSizeSetters.Any(s => s.Window == _window)) return;
|
||||||
{
|
WindowSizeSetter.Make(_window, _window.Position);
|
||||||
WindowSizeSetter.make(window, window.position);
|
Close();
|
||||||
Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length > 0)
|
if (Program.Ctx.WindowSizeSetters.All(s => s.Window != _window)) return;
|
||||||
{
|
WindowSizeSetter.TryRemove(_window);
|
||||||
WindowSizeSetter.TryRemove(window);
|
Close();
|
||||||
Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,112 +6,102 @@ using System.Security.AccessControl;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using CC_Functions.W32;
|
using CC_Functions.W32.Hooks;
|
||||||
using Resizor.Properties;
|
using Resizor.Properties;
|
||||||
using Timer = System.Windows.Forms.Timer;
|
using Timer = System.Windows.Forms.Timer;
|
||||||
|
|
||||||
namespace Resizor
|
namespace Resizor
|
||||||
{
|
{
|
||||||
static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
public static KeyboardHook kh;
|
public static KeyboardHook Kh;
|
||||||
public static NIApplicationContext ctx;
|
public static NiApplicationContext Ctx;
|
||||||
public static immResize rez;
|
private static ImmResize _rez;
|
||||||
|
|
||||||
|
private static NotifyIcon _notifyIcon;
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
private static void Main()
|
||||||
{
|
{
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
string appGuid = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value.ToString();
|
string appGuid = ((GuidAttribute) Assembly.GetExecutingAssembly()
|
||||||
string mutexId = string.Format("Global\\{{{0}}}", appGuid);
|
.GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value;
|
||||||
bool createdNew;
|
MutexAccessRule allowEveryoneRule = new MutexAccessRule(
|
||||||
var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow);
|
new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl,
|
||||||
var securitySettings = new MutexSecurity();
|
AccessControlType.Allow);
|
||||||
|
MutexSecurity securitySettings = new MutexSecurity();
|
||||||
securitySettings.AddAccessRule(allowEveryoneRule);
|
securitySettings.AddAccessRule(allowEveryoneRule);
|
||||||
using (var mutex = new Mutex(false, mutexId, out createdNew, securitySettings))
|
using Mutex mutex = new Mutex(false, $"Global\\{{{appGuid}}}", out bool _);
|
||||||
|
bool hasHandle = false;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var hasHandle = false;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
try
|
hasHandle = mutex.WaitOne(5000, false);
|
||||||
{
|
if (hasHandle == false)
|
||||||
hasHandle = mutex.WaitOne(5000, false);
|
throw new TimeoutException("Timeout waiting for exclusive access");
|
||||||
if (hasHandle == false)
|
|
||||||
throw new TimeoutException("Timeout waiting for exclusive access");
|
|
||||||
}
|
|
||||||
catch (AbandonedMutexException)
|
|
||||||
{
|
|
||||||
#if DEBUG
|
|
||||||
Console.WriteLine("Mutex abandoned");
|
|
||||||
#endif
|
|
||||||
hasHandle = true;
|
|
||||||
}
|
|
||||||
notifyIcon = new NotifyIcon();
|
|
||||||
ContextMenu contextMenu = new ContextMenu();
|
|
||||||
MenuItem settings = new MenuItem();
|
|
||||||
MenuItem exititem = new MenuItem();
|
|
||||||
contextMenu.MenuItems.AddRange(new MenuItem[] { settings, exititem });
|
|
||||||
settings.Index = 0;
|
|
||||||
settings.Text = "Settings";
|
|
||||||
settings.Click += new EventHandler(openSettings);
|
|
||||||
exititem.Index = 1;
|
|
||||||
exititem.Text = "Exit";
|
|
||||||
exititem.Click += new EventHandler(exit);
|
|
||||||
notifyIcon.Icon = Resources.Resizor;
|
|
||||||
notifyIcon.Text = "Resizor";
|
|
||||||
notifyIcon.ContextMenu = contextMenu;
|
|
||||||
notifyIcon.Visible = true;
|
|
||||||
kh = new KeyboardHook();
|
|
||||||
kh.OnKeyPress += keyDown;
|
|
||||||
ctx = new NIApplicationContext();
|
|
||||||
Application.Run(ctx);
|
|
||||||
kh.Dispose();
|
|
||||||
notifyIcon.Visible = false;
|
|
||||||
}
|
}
|
||||||
finally
|
catch (AbandonedMutexException)
|
||||||
{
|
{
|
||||||
if (hasHandle)
|
#if DEBUG
|
||||||
mutex.ReleaseMutex();
|
Console.WriteLine("Mutex abandoned");
|
||||||
|
#endif
|
||||||
|
hasHandle = true;
|
||||||
}
|
}
|
||||||
|
_notifyIcon = new NotifyIcon();
|
||||||
|
ContextMenuStrip contextMenu = new ContextMenuStrip();
|
||||||
|
contextMenu.Items.Add("Settings").Click += OpenSettings;
|
||||||
|
contextMenu.Items.Add("Exit").Click += Exit;
|
||||||
|
_notifyIcon.Icon = Resources.Resizor;
|
||||||
|
_notifyIcon.Text = "Resizor";
|
||||||
|
_notifyIcon.ContextMenuStrip = contextMenu;
|
||||||
|
_notifyIcon.Visible = true;
|
||||||
|
Kh = new KeyboardHook();
|
||||||
|
Kh.OnKeyPress += KeyDown;
|
||||||
|
Ctx = new NiApplicationContext();
|
||||||
|
Application.Run(Ctx);
|
||||||
|
Kh.Dispose();
|
||||||
|
_notifyIcon.Visible = false;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (hasHandle)
|
||||||
|
mutex.ReleaseMutex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void keyDown(KeyboardHookEventArgs e)
|
private static void KeyDown(KeyboardHookEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Key == Settings.Default.ImmediateResizeKey && (rez == null || rez.IsDisposed))
|
if (e.Key != Settings.Default.ImmediateResizeKey || (_rez != null && !_rez.IsDisposed)) return;
|
||||||
{
|
_rez = new ImmResize();
|
||||||
rez = new immResize();
|
_rez.Show();
|
||||||
rez.Show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NotifyIcon notifyIcon;
|
private static void OpenSettings(object sender, EventArgs e) => new SettingsForm().Show();
|
||||||
private static void openSettings(object sender, EventArgs e) => new SettingsForm().Show();
|
private static void Exit(object sender, EventArgs e) => Application.Exit();
|
||||||
private static void exit(object Sender, EventArgs e) => Application.Exit();
|
|
||||||
public class NIApplicationContext : ApplicationContext
|
public class NiApplicationContext : ApplicationContext
|
||||||
{
|
{
|
||||||
public List<WindowSizeSetter> windowSizeSetters = new List<WindowSizeSetter>();
|
public readonly List<WindowSizeSetter> WindowSizeSetters = new List<WindowSizeSetter>();
|
||||||
Timer tim;
|
|
||||||
public NIApplicationContext()
|
public NiApplicationContext()
|
||||||
{
|
{
|
||||||
tim = new Timer();
|
Timer tim = new Timer {Enabled = true, Interval = 100};
|
||||||
tim.Enabled = true;
|
tim.Tick += Tick;
|
||||||
tim.Interval = 100;
|
|
||||||
tim.Tick += tick;
|
|
||||||
}
|
}
|
||||||
private void tick(object sender, EventArgs e)
|
|
||||||
|
private void Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
List<int> toRemove = new List<int>();
|
List<int> toRemove = new List<int>();
|
||||||
for (int i = 0; i < windowSizeSetters.Count; i++)
|
for (int i = 0; i < WindowSizeSetters.Count; i++)
|
||||||
{
|
if (WindowSizeSetters[i].Window.StillExists)
|
||||||
if (windowSizeSetters[i].Window.stillExists)
|
WindowSizeSetters[i].Window.Position = WindowSizeSetters[i].Pos;
|
||||||
windowSizeSetters[i].Window.position = windowSizeSetters[i].Pos;
|
|
||||||
else
|
else
|
||||||
toRemove.Add(i);
|
toRemove.Add(i);
|
||||||
}
|
|
||||||
for (int i = 0; i < toRemove.Count; i++)
|
for (int i = 0; i < toRemove.Count; i++)
|
||||||
windowSizeSetters.RemoveAt(toRemove[i]);
|
WindowSizeSetters.RemoveAt(toRemove[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
|
@ -33,4 +32,4 @@ using System.Runtime.InteropServices;
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.1")]
|
[assembly: AssemblyVersion("1.0.0.1")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.1")]
|
[assembly: AssemblyFileVersion("1.0.0.1")]
|
|
@ -1,106 +1,19 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{EED8B478-D539-41D2-9A39-8349099B298A}</ProjectGuid>
|
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>Resizor</RootNamespace>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<AssemblyName>Resizor</AssemblyName>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
|
||||||
<Deterministic>true</Deterministic>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationIcon>Resizor.ico</ApplicationIcon>
|
<ApplicationIcon>Resizor.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Deployment" />
|
|
||||||
<Reference Include="System.Drawing" />
|
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Windows.Forms" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Immediate Resize.cs">
|
|
||||||
<SubType>Form</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Immediate Resize.Designer.cs">
|
|
||||||
<DependentUpon>Immediate Resize.cs</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="Program.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="SettingsForm.cs">
|
|
||||||
<SubType>Form</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="SettingsForm.Designer.cs">
|
|
||||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="WindowSizeSetter.cs" />
|
|
||||||
<EmbeddedResource Include="Immediate Resize.resx">
|
|
||||||
<DependentUpon>Immediate Resize.cs</DependentUpon>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
</Compile>
|
|
||||||
<EmbeddedResource Include="SettingsForm.resx">
|
|
||||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<None Include="Properties\Settings.settings">
|
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
|
||||||
</None>
|
|
||||||
<Compile Include="Properties\Settings.Designer.cs">
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>Settings.settings</DependentUpon>
|
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="App.config" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Resizor.ico" />
|
<Content Include="Resizor.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\CC-Functions\W32\W32.csproj">
|
<PackageReference Include="CC-Functions.W32" Version="1.0.6" />
|
||||||
<Project>{23de4ae0-5075-4ccc-8440-4d131ca0fbba}</Project>
|
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||||
<Name>W32</Name>
|
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
</Project>
|
|
@ -1,33 +1,34 @@
|
||||||
using CC_Functions.W32;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Resizor.Properties;
|
using CC_Functions.W32.Hooks;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
using Resizor.Properties;
|
||||||
|
|
||||||
namespace Resizor
|
namespace Resizor
|
||||||
{
|
{
|
||||||
public partial class SettingsForm : Form
|
public partial class SettingsForm : Form
|
||||||
{
|
{
|
||||||
RegistryKey rkApp;
|
private const string AppName = "Resizor";
|
||||||
string appName = "Rasizor";
|
private readonly RegistryKey _rkApp;
|
||||||
|
|
||||||
public SettingsForm()
|
public SettingsForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Program.kh = new KeyboardHook();
|
Program.Kh = new KeyboardHook();
|
||||||
keySelectButton.Text = Settings.Default.ImmediateResizeKey.ToString();
|
keySelectButton.Text = Settings.Default.ImmediateResizeKey.ToString();
|
||||||
keySelectButton.Tag = false;
|
keySelectButton.Tag = false;
|
||||||
rowsSelect.Value = Settings.Default.ResizeDividor.Y;
|
rowsSelect.Value = Settings.Default.ResizeDividor.Y;
|
||||||
columnsSelect.Value = Settings.Default.ResizeDividor.X;
|
columnsSelect.Value = Settings.Default.ResizeDividor.X;
|
||||||
rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
|
_rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
|
||||||
startupBox.Checked = rkApp.GetValue(appName) != null;
|
startupBox.Checked = _rkApp.GetValue(AppName) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void KeySelectButton_Click(object sender, EventArgs e)
|
private void KeySelectButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if ((bool)keySelectButton.Tag)
|
if ((bool) keySelectButton.Tag)
|
||||||
{
|
{
|
||||||
Program.kh.OnKeyPress -= Hook_OnKeyPress;
|
Program.Kh.OnKeyPress -= Hook_OnKeyPress;
|
||||||
keySelectButton.BackColor = SystemColors.Control;
|
keySelectButton.BackColor = SystemColors.Control;
|
||||||
keySelectButton.Tag = false;
|
keySelectButton.Tag = false;
|
||||||
keySelectButton.Text = Settings.Default.ImmediateResizeKey.ToString();
|
keySelectButton.Text = Settings.Default.ImmediateResizeKey.ToString();
|
||||||
|
@ -37,13 +38,13 @@ namespace Resizor
|
||||||
keySelectButton.BackColor = Color.Red;
|
keySelectButton.BackColor = Color.Red;
|
||||||
keySelectButton.Text = "Cancel";
|
keySelectButton.Text = "Cancel";
|
||||||
keySelectButton.Tag = true;
|
keySelectButton.Tag = true;
|
||||||
Program.kh.OnKeyPress += Hook_OnKeyPress;
|
Program.Kh.OnKeyPress += Hook_OnKeyPress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Hook_OnKeyPress(KeyboardHookEventArgs e)
|
private void Hook_OnKeyPress(KeyboardHookEventArgs e)
|
||||||
{
|
{
|
||||||
Program.kh.OnKeyPress -= Hook_OnKeyPress;
|
Program.Kh.OnKeyPress -= Hook_OnKeyPress;
|
||||||
keySelectButton.BackColor = SystemColors.Control;
|
keySelectButton.BackColor = SystemColors.Control;
|
||||||
if (e.Key != Keys.Escape)
|
if (e.Key != Keys.Escape)
|
||||||
{
|
{
|
||||||
|
@ -57,7 +58,7 @@ namespace Resizor
|
||||||
private void RowsSelect_ValueChanged(object sender, EventArgs e)
|
private void RowsSelect_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Point tmp = Settings.Default.ResizeDividor;
|
Point tmp = Settings.Default.ResizeDividor;
|
||||||
tmp.Y = (int)rowsSelect.Value;
|
tmp.Y = (int) rowsSelect.Value;
|
||||||
Settings.Default.ResizeDividor = tmp;
|
Settings.Default.ResizeDividor = tmp;
|
||||||
Settings.Default.Save();
|
Settings.Default.Save();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +66,7 @@ namespace Resizor
|
||||||
private void ColumnsSelect_ValueChanged(object sender, EventArgs e)
|
private void ColumnsSelect_ValueChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Point tmp = Settings.Default.ResizeDividor;
|
Point tmp = Settings.Default.ResizeDividor;
|
||||||
tmp.X = (int)columnsSelect.Value;
|
tmp.X = (int) columnsSelect.Value;
|
||||||
Settings.Default.ResizeDividor = tmp;
|
Settings.Default.ResizeDividor = tmp;
|
||||||
Settings.Default.Save();
|
Settings.Default.Save();
|
||||||
}
|
}
|
||||||
|
@ -75,16 +76,16 @@ namespace Resizor
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (startupBox.Checked)
|
if (startupBox.Checked)
|
||||||
rkApp.SetValue(appName, Application.ExecutablePath.ToString());
|
_rkApp.SetValue(AppName, Application.ExecutablePath);
|
||||||
else
|
else
|
||||||
rkApp.DeleteValue(appName, false);
|
_rkApp.DeleteValue(AppName, false);
|
||||||
startupBox.Checked = rkApp.GetValue(appName) != null;
|
startupBox.Checked = _rkApp.GetValue(AppName) != null;
|
||||||
}
|
}
|
||||||
catch (Exception e1)
|
catch (Exception e1)
|
||||||
{
|
{
|
||||||
startupBox.Checked = rkApp.GetValue(appName) != null;
|
startupBox.Checked = _rkApp.GetValue(AppName) != null;
|
||||||
MessageBox.Show(e1.ToString(), "Failed");
|
MessageBox.Show(e1.ToString(), "Failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,40 +8,39 @@ namespace Resizor
|
||||||
{
|
{
|
||||||
public readonly Wnd32 Window;
|
public readonly Wnd32 Window;
|
||||||
public Rectangle Pos;
|
public Rectangle Pos;
|
||||||
WindowSizeSetter(Wnd32 window, Rectangle pos)
|
|
||||||
|
private WindowSizeSetter(Wnd32 window, Rectangle pos)
|
||||||
{
|
{
|
||||||
Window = window;
|
Window = window;
|
||||||
Pos = pos;
|
Pos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void make(Wnd32 window, Rectangle pos)
|
public static void Make(Wnd32 window, Rectangle pos)
|
||||||
{
|
{
|
||||||
WindowSizeSetter[] match = Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray();
|
WindowSizeSetter[] match = Program.Ctx.WindowSizeSetters.Where(s => s.Window == window).ToArray();
|
||||||
switch (match.Length)
|
switch (match.Length)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
Program.ctx.windowSizeSetters.Add(new WindowSizeSetter(window, pos));
|
Program.Ctx.WindowSizeSetters.Add(new WindowSizeSetter(window, pos));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
match[0].Pos = pos;
|
match[0].Pos = pos;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for (int i = 0; i < match.Length; i++)
|
for (int i = 0; i < match.Length; i++)
|
||||||
{
|
|
||||||
if (i == match.Length - 1)
|
if (i == match.Length - 1)
|
||||||
match[0].Pos = pos;
|
match[0].Pos = pos;
|
||||||
else
|
else
|
||||||
Program.ctx.windowSizeSetters.Remove(match[i]);
|
Program.Ctx.WindowSizeSetters.Remove(match[i]);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TryRemove(Wnd32 window)
|
public static void TryRemove(Wnd32 window)
|
||||||
{
|
{
|
||||||
WindowSizeSetter[] match = Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray();
|
WindowSizeSetter[] match = Program.Ctx.WindowSizeSetters.Where(s => s.Window == window).ToArray();
|
||||||
if (match.Length > 0)
|
if (match.Length > 0)
|
||||||
Program.ctx.windowSizeSetters.RemoveAll(Window => Window.Window == window);
|
Program.Ctx.WindowSizeSetters.RemoveAll(s => s.Window == window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="CC-Functions.W32" version="1.0.6" targetFramework="net472" />
|
||||||
|
</packages>
|
Reference in New Issue