/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 |