Widow – Diff between revs 14 and 18

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 14 Rev 18
Line 1... Line 1...
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
-   3 using System.Diagnostics;
-   4 using System.Drawing;
3 using System.Threading.Tasks; 5 using System.Threading.Tasks;
4 using System.Windows.Forms; 6 using System.Windows.Forms;
5 using Windows; 7 using Windows;
-   8 using Gma.System.MouseKeyHook;
Line 6... Line 9...
6   9  
7 namespace Widow 10 namespace Widow
8 { 11 {
9 public partial class RuleEditForm : Form 12 public partial class RuleEditForm : Form
Line 14... Line 17...
14   17  
Line 15... Line 18...
15 public MainForm Form { get; set; } 18 public MainForm Form { get; set; }
Line -... Line 19...
-   19  
-   20 public DrawOverlayForm DrawOverlayForm { get; set; }
16   21  
Line 17... Line 22...
17 public DrawOverlayForm DrawOverlayForm { get; set; } 22 public IKeyboardMouseEvents GlobalMouseHook { get; set; }
Line 18... Line 23...
18   23  
Line 359... Line 364...
359 DrawOverlayForm.WindowDrawn -= DrawOverlayForm_WindowDrawn; 364 DrawOverlayForm.WindowDrawn -= DrawOverlayForm_WindowDrawn;
360 DrawOverlayForm.Dispose(); 365 DrawOverlayForm.Dispose();
361 DrawOverlayForm = null; 366 DrawOverlayForm = null;
362 } 367 }
Line -... Line 368...
-   368  
-   369 private void PickButton_Click(object sender, EventArgs e)
-   370 {
-   371 // Start global mouse key hook.
-   372 GlobalMouseHook = Hook.GlobalEvents();
-   373 GlobalMouseHook.MouseClick += GlobalMouseHook_MouseClick;
-   374  
-   375 // Set cross cursor.
-   376 foreach (var cursor in Enum.GetValues(typeof(Natives.OCR_SYSTEM_CURSORS)))
-   377 {
-   378 Natives.SetSystemCursor(
-   379 Natives.CopyIcon(Natives.LoadCursor(IntPtr.Zero, (int) Natives.OCR_SYSTEM_CURSORS.OCR_CROSS)),
-   380 (uint) cursor);
-   381 }
-   382 }
-   383  
-   384 private void GlobalMouseHook_MouseClick(object sender, MouseEventArgs e)
-   385 {
-   386 var hWnd = Natives.WindowFromPoint(new Point(e.X, e.Y));
-   387 Natives.GetWindowThreadProcessId(hWnd, out var pid);
-   388 var process = Process.GetProcessById((int) pid);
-   389 var windowTitle = Helpers.GetWindowTitle(process.MainWindowHandle);
-   390 if (string.IsNullOrEmpty(windowTitle))
-   391 {
-   392 return;
-   393 }
-   394  
-   395 var windowClass = Helpers.GetWindowClass(process.MainWindowHandle);
-   396 if (string.IsNullOrEmpty(windowClass))
-   397 {
-   398 return;
-   399 }
-   400  
-   401 if (!Natives.GetWindowRect(process.MainWindowHandle, out var rect))
-   402 {
-   403 return;
-   404 }
-   405  
-   406 var window = new Window(windowClass, windowTitle, rect.Top, rect.Left, rect.Right - rect.Left,
-   407 rect.Bottom - rect.Top);
-   408  
-   409 var found = false;
-   410 foreach (var windowRule in windowRulesListBox.Items)
-   411 {
-   412 if (((Window) windowRule).Title != window.Title)
-   413 {
-   414 continue;
-   415 }
-   416  
-   417 found = true;
-   418 break;
-   419 }
-   420  
-   421 if (found)
-   422 {
-   423 return;
-   424 }
-   425  
-   426 windowRulesListBox.Items.Add(window);
-   427 Windows.Window.Add(window);
-   428  
-   429 // Revert cursor.
-   430 Natives.SystemParametersInfo(0x0057, 0, null, 0);
-   431  
-   432 // Remove global mouse key hook.
-   433 GlobalMouseHook.MouseClick -= GlobalMouseHook_MouseClick;
-   434 GlobalMouseHook.Dispose();
-   435 GlobalMouseHook = null;
-   436 }
363   437  
Line 364... Line 438...
364 #endregion 438 #endregion
Line 365... Line 439...
365   439