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
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resizor", "Resizor\Resizor.csproj", "{EED8B478-D539-41D2-9A39-8349099B298A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "W32", "..\CC-Functions\W32\W32.csproj", "{23DE4AE0-5075-4CCC-8440-4D131CA0FBBA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace Resizor
|
||||
{
|
||||
partial class immResize
|
||||
partial class ImmResize
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
|
@ -55,7 +55,7 @@
|
|||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "immResize";
|
||||
this.Name = "ImmResize";
|
||||
this.Opacity = 0.5D;
|
||||
this.ShowIcon = false;
|
||||
this.ShowInTaskbar = false;
|
||||
|
|
|
@ -1,47 +1,49 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using CC_Functions.W32;
|
||||
using CC_Functions.W32.Hooks;
|
||||
using Resizor.Properties;
|
||||
|
||||
namespace Resizor
|
||||
{
|
||||
public partial class immResize : Form
|
||||
public partial class ImmResize : Form
|
||||
{
|
||||
bool down;
|
||||
Point startP;
|
||||
Wnd32 window;
|
||||
Rectangle prevR;
|
||||
Rectangle screen = Screen.PrimaryScreen.WorkingArea;
|
||||
public immResize()
|
||||
private readonly Wnd32 _window;
|
||||
private bool _down;
|
||||
private Rectangle _prevR;
|
||||
private Rectangle _screen = Screen.PrimaryScreen.WorkingArea;
|
||||
private Point _startP;
|
||||
|
||||
public ImmResize()
|
||||
{
|
||||
prevR = new Rectangle();
|
||||
window = Wnd32.foreground();
|
||||
_prevR = new Rectangle();
|
||||
_window = Wnd32.Foreground;
|
||||
InitializeComponent();
|
||||
Program.kh.OnKeyPress += onKeyDown;
|
||||
Rectangle tmp = window.position;
|
||||
Program.Kh.OnKeyPress += OnKeyDown;
|
||||
Rectangle tmp = _window.Position;
|
||||
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();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Wnd32 self = Wnd32.fromForm(this);
|
||||
self.MakeOverlay();
|
||||
if (self != window)
|
||||
self.isForeground = true;
|
||||
Wnd32 self = this.GetWnd32();
|
||||
self.Overlay = true;
|
||||
if (self != _window)
|
||||
self.IsForeground = true;
|
||||
}
|
||||
|
||||
private void Form1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
Graphics g = e.Graphics;
|
||||
|
@ -51,69 +53,63 @@ namespace Resizor
|
|||
g.CompositingQuality = CompositingQuality.HighSpeed;
|
||||
g.PixelOffsetMode = PixelOffsetMode.None;
|
||||
PointF divisor = Settings.Default.ResizeDividor;
|
||||
Rectangle rect;
|
||||
if (down)
|
||||
rect = FRect();
|
||||
else
|
||||
rect = CRect();
|
||||
Rectangle rect = _down ? FRect() : CRect();
|
||||
g.FillRectangle(new SolidBrush(Color.LightBlue), rect);
|
||||
Pen gridPen = new Pen(Color.Black, 2);
|
||||
PointF div = getDiv();
|
||||
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);
|
||||
}
|
||||
PointF div = GetDiv();
|
||||
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.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()));
|
||||
Rectangle FRect()
|
||||
|
||||
private PointF GetDiv() => new PointF(_screen.Width / (float) Settings.Default.ResizeDividor.X,
|
||||
_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 max = c2s(new Point(Math.Max(MousePosition.X, startP.X), Math.Max(MousePosition.Y, startP.Y)), getDiv());
|
||||
return p2r(min, max);
|
||||
Point min = F2S(new Point(Math.Min(MousePosition.X, _startP.X), Math.Min(MousePosition.Y, _startP.Y)),
|
||||
GetDiv());
|
||||
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));
|
||||
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));
|
||||
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);
|
||||
float d2f(double f)
|
||||
|
||||
private static Point F2S(Point p, PointF step) => new Point(F2S(p.X, step.X), F2S(p.Y, step.Y));
|
||||
private static Point C2S(Point p, PointF step) => new Point(C2S(p.X, step.X), C2S(p.Y, step.Y));
|
||||
|
||||
private static 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 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;
|
||||
if (float.IsPositiveInfinity(result))
|
||||
return float.MaxValue;
|
||||
else if (float.IsNegativeInfinity(result))
|
||||
return float.MinValue;
|
||||
return result;
|
||||
float result = (float) f;
|
||||
return float.IsPositiveInfinity(result) ? float.MaxValue :
|
||||
float.IsNegativeInfinity(result) ? float.MinValue : result;
|
||||
}
|
||||
|
||||
private void Form1_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
down = true;
|
||||
startP = MousePosition;
|
||||
_down = true;
|
||||
_startP = MousePosition;
|
||||
}
|
||||
|
||||
private void Form1_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
Rectangle rect;
|
||||
if (down)
|
||||
rect = FRect();
|
||||
else
|
||||
rect = CRect();
|
||||
if (prevR != rect)
|
||||
Rectangle rect = _down ? FRect() : CRect();
|
||||
if (_prevR != rect)
|
||||
Invalidate();
|
||||
prevR = rect;
|
||||
_prevR = rect;
|
||||
}
|
||||
|
||||
private void Form1_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
window.position = FRect();
|
||||
_window.Position = FRect();
|
||||
Close();
|
||||
}
|
||||
|
||||
|
@ -121,20 +117,16 @@ namespace Resizor
|
|||
{
|
||||
if (forcePos.Checked)
|
||||
{
|
||||
if (Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length == 0)
|
||||
{
|
||||
WindowSizeSetter.make(window, window.position);
|
||||
Close();
|
||||
}
|
||||
if (Program.Ctx.WindowSizeSetters.Any(s => s.Window == _window)) return;
|
||||
WindowSizeSetter.Make(_window, _window.Position);
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Program.ctx.windowSizeSetters.Where(Window => Window.Window == window).ToArray().Length > 0)
|
||||
{
|
||||
WindowSizeSetter.TryRemove(window);
|
||||
Close();
|
||||
}
|
||||
if (Program.Ctx.WindowSizeSetters.All(s => s.Window != _window)) return;
|
||||
WindowSizeSetter.TryRemove(_window);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,112 +6,102 @@ using System.Security.AccessControl;
|
|||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using CC_Functions.W32;
|
||||
using CC_Functions.W32.Hooks;
|
||||
using Resizor.Properties;
|
||||
using Timer = System.Windows.Forms.Timer;
|
||||
|
||||
namespace Resizor
|
||||
{
|
||||
static class Program
|
||||
internal static class Program
|
||||
{
|
||||
public static KeyboardHook kh;
|
||||
public static NIApplicationContext ctx;
|
||||
public static immResize rez;
|
||||
public static KeyboardHook Kh;
|
||||
public static NiApplicationContext Ctx;
|
||||
private static ImmResize _rez;
|
||||
|
||||
private static NotifyIcon _notifyIcon;
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
private static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
string appGuid = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value.ToString();
|
||||
string mutexId = string.Format("Global\\{{{0}}}", appGuid);
|
||||
bool createdNew;
|
||||
var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow);
|
||||
var securitySettings = new MutexSecurity();
|
||||
string appGuid = ((GuidAttribute) Assembly.GetExecutingAssembly()
|
||||
.GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value;
|
||||
MutexAccessRule allowEveryoneRule = new MutexAccessRule(
|
||||
new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl,
|
||||
AccessControlType.Allow);
|
||||
MutexSecurity securitySettings = new MutexSecurity();
|
||||
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
|
||||
{
|
||||
hasHandle = mutex.WaitOne(5000, false);
|
||||
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;
|
||||
hasHandle = mutex.WaitOne(5000, false);
|
||||
if (hasHandle == false)
|
||||
throw new TimeoutException("Timeout waiting for exclusive access");
|
||||
}
|
||||
finally
|
||||
catch (AbandonedMutexException)
|
||||
{
|
||||
if (hasHandle)
|
||||
mutex.ReleaseMutex();
|
||||
#if DEBUG
|
||||
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))
|
||||
{
|
||||
rez = new immResize();
|
||||
rez.Show();
|
||||
}
|
||||
if (e.Key != Settings.Default.ImmediateResizeKey || (_rez != null && !_rez.IsDisposed)) return;
|
||||
_rez = new ImmResize();
|
||||
_rez.Show();
|
||||
}
|
||||
|
||||
private static NotifyIcon notifyIcon;
|
||||
private static void openSettings(object sender, EventArgs e) => new SettingsForm().Show();
|
||||
private static void exit(object Sender, EventArgs e) => Application.Exit();
|
||||
public class NIApplicationContext : ApplicationContext
|
||||
private static void OpenSettings(object sender, EventArgs e) => new SettingsForm().Show();
|
||||
private static void Exit(object sender, EventArgs e) => Application.Exit();
|
||||
|
||||
public class NiApplicationContext : ApplicationContext
|
||||
{
|
||||
public List<WindowSizeSetter> windowSizeSetters = new List<WindowSizeSetter>();
|
||||
Timer tim;
|
||||
public NIApplicationContext()
|
||||
public readonly List<WindowSizeSetter> WindowSizeSetters = new List<WindowSizeSetter>();
|
||||
|
||||
public NiApplicationContext()
|
||||
{
|
||||
tim = new Timer();
|
||||
tim.Enabled = true;
|
||||
tim.Interval = 100;
|
||||
tim.Tick += tick;
|
||||
Timer tim = new Timer {Enabled = true, 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>();
|
||||
for (int i = 0; i < windowSizeSetters.Count; i++)
|
||||
{
|
||||
if (windowSizeSetters[i].Window.stillExists)
|
||||
windowSizeSetters[i].Window.position = windowSizeSetters[i].Pos;
|
||||
for (int i = 0; i < WindowSizeSetters.Count; i++)
|
||||
if (WindowSizeSetters[i].Window.StillExists)
|
||||
WindowSizeSetters[i].Window.Position = WindowSizeSetters[i].Pos;
|
||||
else
|
||||
toRemove.Add(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.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
@ -33,4 +32,4 @@ using System.Runtime.InteropServices;
|
|||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[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 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')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{EED8B478-D539-41D2-9A39-8349099B298A}</ProjectGuid>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>Resizor</RootNamespace>
|
||||
<AssemblyName>Resizor</AssemblyName>
|
||||
<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>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>Resizor.ico</ApplicationIcon>
|
||||
</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>
|
||||
<Content Include="Resizor.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\CC-Functions\W32\W32.csproj">
|
||||
<Project>{23de4ae0-5075-4ccc-8440-4d131ca0fbba}</Project>
|
||||
<Name>W32</Name>
|
||||
</ProjectReference>
|
||||
<PackageReference Include="CC-Functions.W32" Version="1.0.6" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -1,33 +1,34 @@
|
|||
using CC_Functions.W32;
|
||||
using System;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Resizor.Properties;
|
||||
using CC_Functions.W32.Hooks;
|
||||
using Microsoft.Win32;
|
||||
using Resizor.Properties;
|
||||
|
||||
namespace Resizor
|
||||
{
|
||||
public partial class SettingsForm : Form
|
||||
{
|
||||
RegistryKey rkApp;
|
||||
string appName = "Rasizor";
|
||||
private const string AppName = "Resizor";
|
||||
private readonly RegistryKey _rkApp;
|
||||
|
||||
public SettingsForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
Program.kh = new KeyboardHook();
|
||||
Program.Kh = new KeyboardHook();
|
||||
keySelectButton.Text = Settings.Default.ImmediateResizeKey.ToString();
|
||||
keySelectButton.Tag = false;
|
||||
rowsSelect.Value = Settings.Default.ResizeDividor.Y;
|
||||
columnsSelect.Value = Settings.Default.ResizeDividor.X;
|
||||
rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
|
||||
startupBox.Checked = rkApp.GetValue(appName) != null;
|
||||
_rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
|
||||
startupBox.Checked = _rkApp.GetValue(AppName) != null;
|
||||
}
|
||||
|
||||
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.Tag = false;
|
||||
keySelectButton.Text = Settings.Default.ImmediateResizeKey.ToString();
|
||||
|
@ -37,13 +38,13 @@ namespace Resizor
|
|||
keySelectButton.BackColor = Color.Red;
|
||||
keySelectButton.Text = "Cancel";
|
||||
keySelectButton.Tag = true;
|
||||
Program.kh.OnKeyPress += Hook_OnKeyPress;
|
||||
Program.Kh.OnKeyPress += Hook_OnKeyPress;
|
||||
}
|
||||
}
|
||||
|
||||
private void Hook_OnKeyPress(KeyboardHookEventArgs e)
|
||||
{
|
||||
Program.kh.OnKeyPress -= Hook_OnKeyPress;
|
||||
Program.Kh.OnKeyPress -= Hook_OnKeyPress;
|
||||
keySelectButton.BackColor = SystemColors.Control;
|
||||
if (e.Key != Keys.Escape)
|
||||
{
|
||||
|
@ -57,7 +58,7 @@ namespace Resizor
|
|||
private void RowsSelect_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
Point tmp = Settings.Default.ResizeDividor;
|
||||
tmp.Y = (int)rowsSelect.Value;
|
||||
tmp.Y = (int) rowsSelect.Value;
|
||||
Settings.Default.ResizeDividor = tmp;
|
||||
Settings.Default.Save();
|
||||
}
|
||||
|
@ -65,7 +66,7 @@ namespace Resizor
|
|||
private void ColumnsSelect_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
Point tmp = Settings.Default.ResizeDividor;
|
||||
tmp.X = (int)columnsSelect.Value;
|
||||
tmp.X = (int) columnsSelect.Value;
|
||||
Settings.Default.ResizeDividor = tmp;
|
||||
Settings.Default.Save();
|
||||
}
|
||||
|
@ -75,16 +76,16 @@ namespace Resizor
|
|||
try
|
||||
{
|
||||
if (startupBox.Checked)
|
||||
rkApp.SetValue(appName, Application.ExecutablePath.ToString());
|
||||
_rkApp.SetValue(AppName, Application.ExecutablePath);
|
||||
else
|
||||
rkApp.DeleteValue(appName, false);
|
||||
startupBox.Checked = rkApp.GetValue(appName) != null;
|
||||
_rkApp.DeleteValue(AppName, false);
|
||||
startupBox.Checked = _rkApp.GetValue(AppName) != null;
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
startupBox.Checked = rkApp.GetValue(appName) != null;
|
||||
startupBox.Checked = _rkApp.GetValue(AppName) != null;
|
||||
MessageBox.Show(e1.ToString(), "Failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,40 +8,39 @@ namespace Resizor
|
|||
{
|
||||
public readonly Wnd32 Window;
|
||||
public Rectangle Pos;
|
||||
WindowSizeSetter(Wnd32 window, Rectangle pos)
|
||||
|
||||
private WindowSizeSetter(Wnd32 window, Rectangle pos)
|
||||
{
|
||||
Window = window;
|
||||
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)
|
||||
{
|
||||
case 0:
|
||||
Program.ctx.windowSizeSetters.Add(new WindowSizeSetter(window, pos));
|
||||
Program.Ctx.WindowSizeSetters.Add(new WindowSizeSetter(window, pos));
|
||||
break;
|
||||
case 1:
|
||||
match[0].Pos = pos;
|
||||
break;
|
||||
default:
|
||||
for (int i = 0; i < match.Length; i++)
|
||||
{
|
||||
if (i == match.Length - 1)
|
||||
match[0].Pos = pos;
|
||||
else
|
||||
Program.ctx.windowSizeSetters.Remove(match[i]);
|
||||
}
|
||||
Program.Ctx.WindowSizeSetters.Remove(match[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
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