/trunk/Widow/RuleEditForm.Designer.cs |
@@ -35,6 +35,10 @@ |
this.refreshButton = new System.Windows.Forms.Button(); |
this.desktopWindowsListBox = new System.Windows.Forms.ListBox(); |
this.addButton = new System.Windows.Forms.Button(); |
this.ignoreLeftCheckBox = new System.Windows.Forms.CheckBox(); |
this.ignoreTopCheckBox = new System.Windows.Forms.CheckBox(); |
this.ignoreWidthCheckBox = new System.Windows.Forms.CheckBox(); |
this.ignoreHeightCheckBox = new System.Windows.Forms.CheckBox(); |
this.groupBox1.SuspendLayout(); |
this.groupBox2.SuspendLayout(); |
this.groupBox7.SuspendLayout(); |
@@ -84,7 +88,7 @@ |
this.groupBox2.Controls.Add(this.groupBox3); |
this.groupBox2.Location = new System.Drawing.Point(382, 12); |
this.groupBox2.Name = "groupBox2"; |
this.groupBox2.Size = new System.Drawing.Size(127, 302); |
this.groupBox2.Size = new System.Drawing.Size(190, 302); |
this.groupBox2.TabIndex = 2; |
this.groupBox2.TabStop = false; |
this.groupBox2.Text = "Settings"; |
@@ -109,10 +113,11 @@ |
// |
// groupBox6 |
// |
this.groupBox6.Controls.Add(this.ignoreHeightCheckBox); |
this.groupBox6.Controls.Add(this.WindowHeight); |
this.groupBox6.Location = new System.Drawing.Point(6, 243); |
this.groupBox6.Name = "groupBox6"; |
this.groupBox6.Size = new System.Drawing.Size(114, 50); |
this.groupBox6.Size = new System.Drawing.Size(178, 50); |
this.groupBox6.TabIndex = 4; |
this.groupBox6.TabStop = false; |
this.groupBox6.Text = "Height"; |
@@ -127,10 +132,11 @@ |
// |
// groupBox5 |
// |
this.groupBox5.Controls.Add(this.ignoreWidthCheckBox); |
this.groupBox5.Controls.Add(this.WindowWidth); |
this.groupBox5.Location = new System.Drawing.Point(6, 187); |
this.groupBox5.Name = "groupBox5"; |
this.groupBox5.Size = new System.Drawing.Size(114, 50); |
this.groupBox5.Size = new System.Drawing.Size(178, 50); |
this.groupBox5.TabIndex = 3; |
this.groupBox5.TabStop = false; |
this.groupBox5.Text = "Width"; |
@@ -145,10 +151,11 @@ |
// |
// groupBox4 |
// |
this.groupBox4.Controls.Add(this.ignoreTopCheckBox); |
this.groupBox4.Controls.Add(this.WindowTop); |
this.groupBox4.Location = new System.Drawing.Point(6, 131); |
this.groupBox4.Name = "groupBox4"; |
this.groupBox4.Size = new System.Drawing.Size(114, 50); |
this.groupBox4.Size = new System.Drawing.Size(178, 50); |
this.groupBox4.TabIndex = 2; |
this.groupBox4.TabStop = false; |
this.groupBox4.Text = "Top"; |
@@ -163,10 +170,11 @@ |
// |
// groupBox3 |
// |
this.groupBox3.Controls.Add(this.ignoreLeftCheckBox); |
this.groupBox3.Controls.Add(this.WindowLeft); |
this.groupBox3.Location = new System.Drawing.Point(6, 75); |
this.groupBox3.Name = "groupBox3"; |
this.groupBox3.Size = new System.Drawing.Size(114, 50); |
this.groupBox3.Size = new System.Drawing.Size(178, 50); |
this.groupBox3.TabIndex = 1; |
this.groupBox3.TabStop = false; |
this.groupBox3.Text = "Left"; |
@@ -219,17 +227,61 @@ |
this.addButton.UseVisualStyleBackColor = true; |
this.addButton.Click += new System.EventHandler(this.AddButton_Click); |
// |
// ignoreLeftCheckBox |
// |
this.ignoreLeftCheckBox.AutoSize = true; |
this.ignoreLeftCheckBox.Location = new System.Drawing.Point(114, 21); |
this.ignoreLeftCheckBox.Name = "ignoreLeftCheckBox"; |
this.ignoreLeftCheckBox.Size = new System.Drawing.Size(56, 17); |
this.ignoreLeftCheckBox.TabIndex = 1; |
this.ignoreLeftCheckBox.Text = "Ignore"; |
this.ignoreLeftCheckBox.UseVisualStyleBackColor = true; |
this.ignoreLeftCheckBox.CheckedChanged += new System.EventHandler(this.OnIgnoreWindowSettings_CheckedChanged); |
// |
// ignoreTopCheckBox |
// |
this.ignoreTopCheckBox.AutoSize = true; |
this.ignoreTopCheckBox.Location = new System.Drawing.Point(114, 21); |
this.ignoreTopCheckBox.Name = "ignoreTopCheckBox"; |
this.ignoreTopCheckBox.Size = new System.Drawing.Size(56, 17); |
this.ignoreTopCheckBox.TabIndex = 2; |
this.ignoreTopCheckBox.Text = "Ignore"; |
this.ignoreTopCheckBox.UseVisualStyleBackColor = true; |
this.ignoreTopCheckBox.CheckedChanged += new System.EventHandler(this.OnIgnoreWindowSettings_CheckedChanged); |
// |
// ignoreWidthCheckBox |
// |
this.ignoreWidthCheckBox.AutoSize = true; |
this.ignoreWidthCheckBox.Location = new System.Drawing.Point(114, 22); |
this.ignoreWidthCheckBox.Name = "ignoreWidthCheckBox"; |
this.ignoreWidthCheckBox.Size = new System.Drawing.Size(56, 17); |
this.ignoreWidthCheckBox.TabIndex = 2; |
this.ignoreWidthCheckBox.Text = "Ignore"; |
this.ignoreWidthCheckBox.UseVisualStyleBackColor = true; |
this.ignoreWidthCheckBox.CheckedChanged += new System.EventHandler(this.OnIgnoreWindowSettings_CheckedChanged); |
// |
// ignoreHeightCheckBox |
// |
this.ignoreHeightCheckBox.AutoSize = true; |
this.ignoreHeightCheckBox.Location = new System.Drawing.Point(114, 21); |
this.ignoreHeightCheckBox.Name = "ignoreHeightCheckBox"; |
this.ignoreHeightCheckBox.Size = new System.Drawing.Size(56, 17); |
this.ignoreHeightCheckBox.TabIndex = 2; |
this.ignoreHeightCheckBox.Text = "Ignore"; |
this.ignoreHeightCheckBox.UseVisualStyleBackColor = true; |
this.ignoreHeightCheckBox.CheckedChanged += new System.EventHandler(this.OnIgnoreWindowSettings_CheckedChanged); |
// |
// RuleEditForm |
// |
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); |
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; |
this.ClientSize = new System.Drawing.Size(524, 362); |
this.ClientSize = new System.Drawing.Size(584, 362); |
this.Controls.Add(this.groupBox8); |
this.Controls.Add(this.groupBox2); |
this.Controls.Add(this.groupBox1); |
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); |
this.MaximumSize = new System.Drawing.Size(540, 400); |
this.MinimumSize = new System.Drawing.Size(540, 400); |
this.MaximumSize = new System.Drawing.Size(600, 400); |
this.MinimumSize = new System.Drawing.Size(600, 400); |
this.Name = "RuleEditForm"; |
this.Text = "Rule Editor"; |
this.groupBox1.ResumeLayout(false); |
@@ -269,5 +321,9 @@ |
private System.Windows.Forms.Button addButton; |
private System.Windows.Forms.Button removeButton; |
private System.Windows.Forms.Button refreshButton; |
private System.Windows.Forms.CheckBox ignoreHeightCheckBox; |
private System.Windows.Forms.CheckBox ignoreWidthCheckBox; |
private System.Windows.Forms.CheckBox ignoreTopCheckBox; |
private System.Windows.Forms.CheckBox ignoreLeftCheckBox; |
} |
} |
/trunk/Widow/RuleEditForm.cs |
@@ -126,9 +126,13 @@ |
if (listBox.SelectedIndex == -1) |
{ |
WindowName.Text = string.Empty; |
ignoreLeftCheckBox.Checked = false; |
WindowLeft.Text = string.Empty; |
ignoreTopCheckBox.Checked = false; |
WindowTop.Text = string.Empty; |
ignoreWidthCheckBox.Checked = false; |
WindowWidth.Text = string.Empty; |
ignoreHeightCheckBox.Checked = false; |
WindowHeight.Text = string.Empty; |
return; |
} |
@@ -141,9 +145,13 @@ |
} |
|
WindowName.Text = window.Name; |
ignoreLeftCheckBox.Checked = window.IgnoreLeft; |
WindowLeft.Text = window.Left.ToString(); |
ignoreTopCheckBox.Checked = window.IgnoreTop; |
WindowTop.Text = window.Top.ToString(); |
ignoreWidthCheckBox.Checked = window.IgnoreWidth; |
WindowWidth.Text = window.Width.ToString(); |
ignoreHeightCheckBox.Checked = window.IgnoreHeight; |
WindowHeight.Text = window.Height.ToString(); |
} |
|
@@ -258,6 +266,38 @@ |
} |
} |
|
private void OnIgnoreWindowSettings_CheckedChanged(object sender, EventArgs e) |
{ |
var selectedWindow = (Window) windowRulesListBox.SelectedItem; |
|
if (selectedWindow == null) |
{ |
ignoreLeftCheckBox.Checked = false; |
ignoreTopCheckBox.Checked = false; |
ignoreWidthCheckBox.Checked = false; |
ignoreHeightCheckBox.Checked = false; |
|
return; |
} |
|
var checkBox = (CheckBox) sender; |
switch (checkBox.Name) |
{ |
case nameof(ignoreHeightCheckBox): |
selectedWindow.IgnoreHeight = checkBox.Checked; |
break; |
case nameof(ignoreWidthCheckBox): |
selectedWindow.IgnoreWidth = checkBox.Checked; |
break; |
case nameof(ignoreTopCheckBox): |
selectedWindow.IgnoreTop = checkBox.Checked; |
break; |
case nameof(ignoreLeftCheckBox): |
selectedWindow.IgnoreLeft = checkBox.Checked; |
break; |
} |
} |
|
#endregion |
|
#region Private Methods |
/trunk/Widow/WindowManipulation.cs |
@@ -0,0 +1,160 @@ |
using System; |
using System.Threading; |
using System.Threading.Tasks; |
using Widow.Properties; |
|
namespace Widow |
{ |
public class WindowManipulation : IDisposable |
{ |
#region Public Enums, Properties and Fields |
|
public bool OnWindowCreate { get; set; } |
|
public int ApplyEveryTime { get; set; } |
|
public bool ApplyEveryTimeEnabled { get; set; } |
|
#endregion |
|
#region Private Delegates, Events, Enums, Properties, Indexers and Fields |
|
private MainForm Form { get; } |
|
private Windows.Windows Windows { get; } |
|
private CancellationTokenSource CancellationTokenSource { get; set; } |
|
private Task ApplyEveryTask { get; } |
|
#endregion |
|
#region Constructors, Destructors and Finalizers |
|
public WindowManipulation() |
{ |
CancellationTokenSource = new CancellationTokenSource(); |
ApplyEveryTask = ApplyEvery(CancellationTokenSource.Token); |
} |
|
public WindowManipulation(MainForm mainForm) : this() |
{ |
Form = mainForm; |
|
Form.WindowCreated += Form_WindowCreated; |
} |
|
public WindowManipulation(MainForm mainForm, Windows.Windows windows) : this(mainForm) |
{ |
Windows = windows; |
} |
|
public WindowManipulation(MainForm mainForm, Windows.Windows windows, Settings settings) : this(mainForm, |
windows) |
{ |
OnWindowCreate = settings.OnWindowCreate; |
ApplyEveryTimeEnabled = settings.ApplyEveryTimeEnabled; |
if (int.TryParse(settings.ApplyEveryTime, out var time)) |
{ |
ApplyEveryTime = time; |
} |
} |
|
public void Dispose() |
{ |
Form.WindowCreated -= Form_WindowCreated; |
CancellationTokenSource.Cancel(); |
ApplyEveryTask.Wait(); |
CancellationTokenSource.Dispose(); |
CancellationTokenSource = null; |
} |
|
#endregion |
|
#region Event Handlers |
|
private void Form_WindowCreated(object sender, WindowCreatedEventArgs e) |
{ |
if (!OnWindowCreate) |
{ |
return; |
} |
|
if (!Windows.Contains(e.Name)) |
{ |
return; |
} |
|
Apply(); |
} |
|
#endregion |
|
#region Public Methods |
|
public void Apply() |
{ |
foreach (var window in Windows.Window) |
{ |
var hWnd = Helpers.FindWindowByTitle(window.Name); |
if (hWnd == IntPtr.Zero) |
{ |
continue; |
} |
|
if (!Natives.GetWindowRect(hWnd, out var rect)) |
{ |
continue; |
} |
|
var left = window.Left; |
if (window.IgnoreLeft) |
{ |
left = rect.Left; |
} |
|
var top = window.Top; |
if (window.IgnoreTop) |
{ |
top = rect.Top; |
} |
|
var width = window.Width; |
if (window.IgnoreWidth) |
{ |
width = rect.Left - rect.Right; |
} |
|
var height = window.Height; |
if (window.IgnoreHeight) |
{ |
height = rect.Top - rect.Bottom; |
} |
|
Natives.MoveWindow(hWnd, left, top, width, height, true); |
} |
} |
|
#endregion |
|
#region Private Methods |
|
private async Task ApplyEvery(CancellationToken cancellationToken) |
{ |
do |
{ |
if (!ApplyEveryTimeEnabled) |
{ |
await Task.Delay(1000, cancellationToken); |
continue; |
} |
|
await Task.Delay(ApplyEveryTime, cancellationToken); |
|
Apply(); |
} while (!cancellationToken.IsCancellationRequested); |
} |
|
#endregion |
} |
} |