Widow

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 17  →  ?path2? @ 18
/trunk/Widow/DrawOverlayForm.Designer.cs
@@ -44,7 +44,6 @@
this.ShowInTaskbar = false;
this.Text = "DrawOverlayForm";
this.TopMost = true;
this.TransparencyKey = System.Drawing.Color.Green;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.DrawOverlayForm_Paint);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.DrawOverlayForm_MouseDown);
/trunk/Widow/DrawOverlayForm.cs
@@ -36,7 +36,7 @@
{
InitializeComponent();
 
DrawBrush = new SolidBrush(Color.Green);
DrawBrush = new SolidBrush(Color.LightBlue);
FormBrush = new SolidBrush(Color.White);
}
 
/trunk/Widow/MainForm.cs
@@ -46,9 +46,11 @@
 
Natives.RegisterShellHookWindow(Handle);
 
WindowManipulation = new WindowManipulation(Settings.Default, this);
 
LoadWindows().ContinueWith(task =>
{
WindowManipulation = new WindowManipulation(this, Windows, Settings.Default);
WindowManipulation.AddWindows(Windows);
});
}
 
/trunk/Widow/Natives.cs
@@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
 
@@ -6,9 +7,6 @@
{
public static class Natives
{
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
 
#region Public Events & Delegates
 
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
@@ -17,6 +15,79 @@
 
#region Public Enums, Properties and Fields
 
public enum OCR_SYSTEM_CURSORS : uint
{
/// <summary>
/// Standard arrow and small hourglass
/// </summary>
OCR_APPSTARTING = 32650,
 
/// <summary>
/// Standard arrow
/// </summary>
OCR_NORMAL = 32512,
 
/// <summary>
/// Crosshair
/// </summary>
OCR_CROSS = 32515,
 
/// <summary>
/// Windows 2000/XP: Hand
/// </summary>
OCR_HAND = 32649,
 
/// <summary>
/// Arrow and question mark
/// </summary>
OCR_HELP = 32651,
 
/// <summary>
/// I-beam
/// </summary>
OCR_IBEAM = 32513,
 
/// <summary>
/// Slashed circle
/// </summary>
OCR_NO = 32648,
 
/// <summary>
/// Four-pointed arrow pointing north, south, east, and west
/// </summary>
OCR_SIZEALL = 32646,
 
/// <summary>
/// Double-pointed arrow pointing northeast and southwest
/// </summary>
OCR_SIZENESW = 32643,
 
/// <summary>
/// Double-pointed arrow pointing north and south
/// </summary>
OCR_SIZENS = 32645,
 
/// <summary>
/// Double-pointed arrow pointing northwest and southeast
/// </summary>
OCR_SIZENWSE = 32642,
 
/// <summary>
/// Double-pointed arrow pointing west and east
/// </summary>
OCR_SIZEWE = 32644,
 
/// <summary>
/// Vertical arrow
/// </summary>
OCR_UP = 32516,
 
/// <summary>
/// Hourglass
/// </summary>
OCR_WAIT = 32514
}
 
/// <summary>
/// Windows Messages
/// Defined in winuser.h from Windows SDK v6.1
@@ -1519,6 +1590,29 @@
#region Public Methods
 
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(Point p);
 
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
 
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(uint uiAction,
uint uiParam, string pvParam, uint fWinIni);
 
 
[DllImport("user32.dll")]
public static extern bool SetSystemCursor(IntPtr hcur, uint id);
 
[DllImport("user32.dll")]
public static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
 
[DllImport("user32.dll")]
public static extern IntPtr CopyIcon(IntPtr pcur);
 
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
 
[DllImport("user32.dll")]
public static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
 
[DllImport("user32.dll")]
/trunk/Widow/RuleEditForm.Designer.cs
@@ -21,6 +21,7 @@
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.removeButton = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.drawButton = new System.Windows.Forms.Button();
this.WindowTitle = new System.Windows.Forms.TextBox();
this.groupBox6 = new System.Windows.Forms.GroupBox();
this.ignoreHeightCheckBox = new System.Windows.Forms.CheckBox();
@@ -38,7 +39,7 @@
this.refreshButton = new System.Windows.Forms.Button();
this.desktopWindowsListBox = new System.Windows.Forms.ListBox();
this.addButton = new System.Windows.Forms.Button();
this.drawButton = new System.Windows.Forms.Button();
this.pickButton = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox6.SuspendLayout();
@@ -60,6 +61,7 @@
//
// groupBox1
//
this.groupBox1.Controls.Add(this.pickButton);
this.groupBox1.Controls.Add(this.windowRulesListBox);
this.groupBox1.Controls.Add(this.removeButton);
this.groupBox1.Location = new System.Drawing.Point(197, 12);
@@ -71,7 +73,7 @@
//
// removeButton
//
this.removeButton.Location = new System.Drawing.Point(6, 302);
this.removeButton.Location = new System.Drawing.Point(87, 302);
this.removeButton.Name = "removeButton";
this.removeButton.Size = new System.Drawing.Size(75, 23);
this.removeButton.TabIndex = 5;
@@ -94,6 +96,16 @@
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Settings";
//
// drawButton
//
this.drawButton.Location = new System.Drawing.Point(14, 299);
this.drawButton.Name = "drawButton";
this.drawButton.Size = new System.Drawing.Size(75, 23);
this.drawButton.TabIndex = 5;
this.drawButton.Text = "Draw";
this.drawButton.UseVisualStyleBackColor = true;
this.drawButton.Click += new System.EventHandler(this.DrawButton_Click);
//
// WindowTitle
//
this.WindowTitle.Location = new System.Drawing.Point(14, 31);
@@ -264,15 +276,15 @@
this.addButton.UseVisualStyleBackColor = true;
this.addButton.Click += new System.EventHandler(this.AddButton_Click);
//
// drawButton
// pickButton
//
this.drawButton.Location = new System.Drawing.Point(14, 299);
this.drawButton.Name = "drawButton";
this.drawButton.Size = new System.Drawing.Size(75, 23);
this.drawButton.TabIndex = 5;
this.drawButton.Text = "Draw";
this.drawButton.UseVisualStyleBackColor = true;
this.drawButton.Click += new System.EventHandler(this.DrawButton_Click);
this.pickButton.Location = new System.Drawing.Point(6, 302);
this.pickButton.Name = "pickButton";
this.pickButton.Size = new System.Drawing.Size(75, 23);
this.pickButton.TabIndex = 6;
this.pickButton.Text = "Pick";
this.pickButton.UseVisualStyleBackColor = true;
this.pickButton.Click += new System.EventHandler(this.PickButton_Click);
//
// RuleEditForm
//
@@ -327,5 +339,6 @@
private System.Windows.Forms.CheckBox ignoreTopCheckBox;
private System.Windows.Forms.CheckBox ignoreLeftCheckBox;
private System.Windows.Forms.Button drawButton;
private System.Windows.Forms.Button pickButton;
}
}
/trunk/Widow/RuleEditForm.cs
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows;
using Gma.System.MouseKeyHook;
 
namespace Widow
{
@@ -16,6 +19,8 @@
 
public DrawOverlayForm DrawOverlayForm { get; set; }
 
public IKeyboardMouseEvents GlobalMouseHook { get; set; }
 
#endregion
 
#region Constructors, Destructors and Finalizers
@@ -361,6 +366,75 @@
DrawOverlayForm = null;
}
 
private void PickButton_Click(object sender, EventArgs e)
{
// Start global mouse key hook.
GlobalMouseHook = Hook.GlobalEvents();
GlobalMouseHook.MouseClick += GlobalMouseHook_MouseClick;
 
// Set cross cursor.
foreach (var cursor in Enum.GetValues(typeof(Natives.OCR_SYSTEM_CURSORS)))
{
Natives.SetSystemCursor(
Natives.CopyIcon(Natives.LoadCursor(IntPtr.Zero, (int) Natives.OCR_SYSTEM_CURSORS.OCR_CROSS)),
(uint) cursor);
}
}
 
private void GlobalMouseHook_MouseClick(object sender, MouseEventArgs e)
{
var hWnd = Natives.WindowFromPoint(new Point(e.X, e.Y));
Natives.GetWindowThreadProcessId(hWnd, out var pid);
var process = Process.GetProcessById((int) pid);
var windowTitle = Helpers.GetWindowTitle(process.MainWindowHandle);
if (string.IsNullOrEmpty(windowTitle))
{
return;
}
 
var windowClass = Helpers.GetWindowClass(process.MainWindowHandle);
if (string.IsNullOrEmpty(windowClass))
{
return;
}
 
if (!Natives.GetWindowRect(process.MainWindowHandle, out var rect))
{
return;
}
 
var window = new Window(windowClass, windowTitle, rect.Top, rect.Left, rect.Right - rect.Left,
rect.Bottom - rect.Top);
 
var found = false;
foreach (var windowRule in windowRulesListBox.Items)
{
if (((Window) windowRule).Title != window.Title)
{
continue;
}
 
found = true;
break;
}
 
if (found)
{
return;
}
 
windowRulesListBox.Items.Add(window);
Windows.Window.Add(window);
 
// Revert cursor.
Natives.SystemParametersInfo(0x0057, 0, null, 0);
 
// Remove global mouse key hook.
GlobalMouseHook.MouseClick -= GlobalMouseHook_MouseClick;
GlobalMouseHook.Dispose();
GlobalMouseHook = null;
}
 
#endregion
 
#region Private Methods
/trunk/Widow/Widow.csproj
@@ -42,6 +42,9 @@
<Reference Include="AutoUpdater.NET, Version=1.6.4.0, Culture=neutral, PublicKeyToken=501435c91b35f4bc, processorArchitecture=MSIL">
<HintPath>..\packages\Autoupdater.NET.Official.1.6.4\lib\net45\AutoUpdater.NET.dll</HintPath>
</Reference>
<Reference Include="Gma.System.MouseKeyHook, Version=5.6.130.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MouseKeyHook.5.6.0\lib\net40\Gma.System.MouseKeyHook.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
/trunk/Widow/WindowManipulation.cs
@@ -25,7 +25,7 @@
 
private MainForm Form { get; }
 
private Windows.Windows WindowsToManipulate { get; }
private Windows.Windows WindowsToManipulate { get; set; }
 
private CancellationTokenSource CancellationTokenSource { get; set; }
 
@@ -58,15 +58,8 @@
Form.WindowCreated += Form_WindowCreated;
}
 
public WindowManipulation(MainForm mainForm, Windows.Windows windowsToManipulate) : this(mainForm)
public WindowManipulation(Settings settings, MainForm mainForm) : this(mainForm)
{
WindowsToManipulate = windowsToManipulate;
}
 
public WindowManipulation(MainForm mainForm, Windows.Windows windowsToManipulate, Settings settings) : this(
mainForm,
windowsToManipulate)
{
OnWindowCreate = settings.OnWindowCreate;
ApplyEveryTimeEnabled = settings.ApplyEveryTimeEnabled;
if (int.TryParse(settings.ApplyEveryTime, out var time))
@@ -98,6 +91,11 @@
return;
}
 
if (WindowsToManipulate == null)
{
return;
}
 
var @class = Helpers.GetWindowClass(e.Handle);
if (!WindowsToManipulate.TryGetWindow(new WindowHash(e.Title, @class), out _))
{
@@ -111,8 +109,18 @@
 
#region Public Methods
 
public void AddWindows(Windows.Windows windows)
{
WindowsToManipulate = windows;
}
 
public async Task Apply()
{
if (WindowsToManipulate == null)
{
return;
}
 
var windows = new List<WindowModification>();
foreach (var hWnd in Helpers.FindWindows((wnd, param) => true))
{
/trunk/Widow/packages.config
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autoupdater.NET.Official" version="1.6.4" targetFramework="net452" />
<package id="MouseKeyHook" version="5.6.0" targetFramework="net452" />
<package id="System.Threading.Tasks.Dataflow" version="5.0.0" targetFramework="net452" />
</packages>