Widow – Diff between revs 25 and 26

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 25 Rev 26
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Diagnostics; 3 using System.Diagnostics;
4 using System.Drawing; 4 using System.Drawing;
5 using System.Threading.Tasks; 5 using System.Threading.Tasks;
6 using System.Windows.Forms; 6 using System.Windows.Forms;
7 using Windows; 7 using Windows;
8 using Gma.System.MouseKeyHook; 8 using Gma.System.MouseKeyHook;
9   9  
10 namespace Widow 10 namespace Widow
11 { 11 {
12 public partial class RuleEditForm : Form 12 public partial class RuleEditForm : Form
13 { 13 {
14 #region Public Enums, Properties and Fields 14 #region Public Enums, Properties and Fields
15   15  
16 public Windows.Windows Windows { get; } 16 public Windows.Windows Windows { get; }
17   17  
18 public MainForm Form { get; set; } 18 public MainForm Form { get; set; }
19   19  
20 public DrawOverlayForm DrawOverlayForm { get; set; } 20 public DrawOverlayForm DrawOverlayForm { get; set; }
21   21  
22 public IKeyboardMouseEvents GlobalMouseHook { get; set; } 22 public IKeyboardMouseEvents GlobalMouseHook { get; set; }
23   23  
24 #endregion 24 #endregion
25   25  
26 #region Constructors, Destructors and Finalizers 26 #region Constructors, Destructors and Finalizers
27   27  
28 public RuleEditForm(MainForm mainForm, Windows.Windows windows) : this(windows) 28 public RuleEditForm(MainForm mainForm, Windows.Windows windows) : this(windows)
29 { 29 {
30 Form = mainForm; 30 Form = mainForm;
31   31  
32 Form.WindowCreated += Form_WindowCreated; 32 Form.WindowCreated += Form_WindowCreated;
33 Form.WindowDestroyed += Form_WindowDestroyed; 33 Form.WindowDestroyed += Form_WindowDestroyed;
34 } 34 }
35   35  
36 public RuleEditForm(Windows.Windows windows) : this() 36 public RuleEditForm(Windows.Windows windows) : this()
37 { 37 {
38 Windows = windows; 38 Windows = windows;
39   39  
40 foreach (var window in windows.Window) 40 foreach (var window in windows.Window)
41 { 41 {
42 windowRulesListBox.Items.Add(window); 42 windowRulesListBox.Items.Add(window);
43 } 43 }
44 } 44 }
45   45  
46 private RuleEditForm() 46 private RuleEditForm()
47 { 47 {
48 InitializeComponent(); 48 InitializeComponent();
49   49  
50 desktopWindowsListBox.DisplayMember = nameof(Window.Title); 50 desktopWindowsListBox.DisplayMember = nameof(Window.Title);
51 desktopWindowsListBox.SetDoubleBuffered(); 51 desktopWindowsListBox.SetDoubleBuffered();
52 windowRulesListBox.DisplayMember = nameof(Window.Title); 52 windowRulesListBox.DisplayMember = nameof(Window.Title);
53 windowRulesListBox.SetDoubleBuffered(); 53 windowRulesListBox.SetDoubleBuffered();
54   54  
55 Task.Run(RefreshWindows); 55 Task.Run(RefreshWindows);
56 } 56 }
57   57  
58 /// <summary> 58 /// <summary>
59 /// Clean up any resources being used. 59 /// Clean up any resources being used.
60 /// </summary> 60 /// </summary>
61 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 61 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
62 protected override void Dispose(bool disposing) 62 protected override void Dispose(bool disposing)
63 { 63 {
64 if (disposing && components != null) 64 if (disposing && components != null)
65 { 65 {
66 Form.WindowCreated -= Form_WindowCreated; 66 Form.WindowCreated -= Form_WindowCreated;
67 Form.WindowDestroyed -= Form_WindowDestroyed; 67 Form.WindowDestroyed -= Form_WindowDestroyed;
68   68  
69 components.Dispose(); 69 components.Dispose();
70 } 70 }
71   71  
72 base.Dispose(disposing); 72 base.Dispose(disposing);
73 } 73 }
74   74  
75 #endregion 75 #endregion
76   76  
77 #region Event Handlers 77 #region Event Handlers
78   78  
79 private void Form_WindowDestroyed(object sender, WindowDestroyedEventArgs e) 79 private void Form_WindowDestroyed(object sender, WindowDestroyedEventArgs e)
80 { 80 {
81 if (string.IsNullOrEmpty(e.Title)) 81 if (string.IsNullOrEmpty(e.Title))
82 { 82 {
83 return; 83 return;
84 } 84 }
85   85  
86 var indices = new List<int>(); 86 var indices = new List<int>();
87 for (var i = 0; i < desktopWindowsListBox.Items.Count; ++i) 87 for (var i = 0; i < desktopWindowsListBox.Items.Count; ++i)
88 { 88 {
89 if (((Window) desktopWindowsListBox.Items[i]).Title == e.Title) 89 if (((Window) desktopWindowsListBox.Items[i]).Title == e.Title)
90 { 90 {
91 indices.Add(i); 91 indices.Add(i);
92 } 92 }
93 } 93 }
94   94  
95 foreach (var index in indices) 95 foreach (var index in indices)
96 { 96 {
97 desktopWindowsListBox.Items.RemoveAt(index); 97 desktopWindowsListBox.Items.RemoveAt(index);
98 } 98 }
99 } 99 }
100   100  
101 private void Form_WindowCreated(object sender, WindowCreatedEventArgs e) 101 private void Form_WindowCreated(object sender, WindowCreatedEventArgs e)
102 { 102 {
103 if (string.IsNullOrEmpty(e.Title)) 103 if (string.IsNullOrEmpty(e.Title))
104 { 104 {
105 return; 105 return;
106 } 106 }
107   107  
108 var found = false; 108 var found = false;
109 foreach (var window in desktopWindowsListBox.Items) 109 foreach (var window in desktopWindowsListBox.Items)
110 { 110 {
111 if (((Window) window).Title == e.Title) 111 if (((Window) window).Title == e.Title)
112 { 112 {
113 found = true; 113 found = true;
114 break; 114 break;
115 } 115 }
116 } 116 }
117   117  
118 if (found) 118 if (found)
119 { 119 {
120 return; 120 return;
121 } 121 }
122   122  
123 if (!Natives.GetWindowRect(e.Handle, out var rect)) 123 if (!Natives.GetWindowRect(e.Handle, out var rect))
124 { 124 {
125 return; 125 return;
126 } 126 }
127   -  
128 string process; -  
129 try -  
130 { 127  
131 process = Helpers.GetProcessName(e.Handle); -  
132 } -  
133 catch -  
134 { -  
135 return; -  
136 } 128 var process = Helpers.GetProcessName(e.Handle);
137   129  
138 if (string.IsNullOrEmpty(process)) 130 if (string.IsNullOrEmpty(process))
139 { 131 {
140 return; 132 return;
141 } 133 }
142   134  
143 var newWindow = new Window(process, e.Title, rect.Top, rect.Left, rect.Right - rect.Left, 135 var newWindow = new Window(process, e.Title, rect.Top, rect.Left, rect.Right - rect.Left,
144 rect.Bottom - rect.Top); 136 rect.Bottom - rect.Top);
145   137  
146 desktopWindowsListBox.Items.Add(newWindow); 138 desktopWindowsListBox.Items.Add(newWindow);
147 } 139 }
148   140  
149 private void WindowRulesListBox_SelectedIndexChanged(object sender, EventArgs e) 141 private void WindowRulesListBox_SelectedIndexChanged(object sender, EventArgs e)
150 { 142 {
151 var listBox = (ListBox) sender; 143 var listBox = (ListBox) sender;
152   144  
153 if (listBox.SelectedIndex == -1) 145 if (listBox.SelectedIndex == -1)
154 { 146 {
155 WindowTitle.Text = string.Empty; 147 WindowTitle.Text = string.Empty;
156 ignoreLeftCheckBox.Checked = false; 148 ignoreLeftCheckBox.Checked = false;
157 WindowLeft.Text = string.Empty; 149 WindowLeft.Text = string.Empty;
158 ignoreTopCheckBox.Checked = false; 150 ignoreTopCheckBox.Checked = false;
159 WindowTop.Text = string.Empty; 151 WindowTop.Text = string.Empty;
160 ignoreWidthCheckBox.Checked = false; 152 ignoreWidthCheckBox.Checked = false;
161 WindowWidth.Text = string.Empty; 153 WindowWidth.Text = string.Empty;
162 ignoreHeightCheckBox.Checked = false; 154 ignoreHeightCheckBox.Checked = false;
163 WindowHeight.Text = string.Empty; 155 WindowHeight.Text = string.Empty;
164 return; 156 return;
165 } 157 }
166   158  
167 var window = (Window) listBox.SelectedItem; 159 var window = (Window) listBox.SelectedItem;
168   160  
169 if (window == null) 161 if (window == null)
170 { 162 {
171 return; 163 return;
172 } 164 }
173   165  
174 WindowTitle.Text = window.Title; 166 WindowTitle.Text = window.Title;
175 ignoreLeftCheckBox.Checked = window.IgnoreLeft; 167 ignoreLeftCheckBox.Checked = window.IgnoreLeft;
176 WindowLeft.Text = window.Left.ToString(); 168 WindowLeft.Text = window.Left.ToString();
177 ignoreTopCheckBox.Checked = window.IgnoreTop; 169 ignoreTopCheckBox.Checked = window.IgnoreTop;
178 WindowTop.Text = window.Top.ToString(); 170 WindowTop.Text = window.Top.ToString();
179 ignoreWidthCheckBox.Checked = window.IgnoreWidth; 171 ignoreWidthCheckBox.Checked = window.IgnoreWidth;
180 WindowWidth.Text = window.Width.ToString(); 172 WindowWidth.Text = window.Width.ToString();
181 ignoreHeightCheckBox.Checked = window.IgnoreHeight; 173 ignoreHeightCheckBox.Checked = window.IgnoreHeight;
182 WindowHeight.Text = window.Height.ToString(); 174 WindowHeight.Text = window.Height.ToString();
183 } 175 }
184   176  
185 private void RefreshButton_Click(object sender, EventArgs e) 177 private void RefreshButton_Click(object sender, EventArgs e)
186 { 178 {
187 Task.Run(RefreshWindows); 179 Task.Run(RefreshWindows);
188 } 180 }
189   181  
190 private void RemoveButton_Click(object sender, EventArgs e) 182 private void RemoveButton_Click(object sender, EventArgs e)
191 { 183 {
192 var window = (Window) windowRulesListBox.SelectedItem; 184 var window = (Window) windowRulesListBox.SelectedItem;
193 if (window == null) 185 if (window == null)
194 { 186 {
195 return; 187 return;
196 } 188 }
197   189  
198 var index = -1; 190 var index = -1;
199 for (var i = 0; i < windowRulesListBox.Items.Count; ++i) 191 for (var i = 0; i < windowRulesListBox.Items.Count; ++i)
200 { 192 {
201 if (((Window) windowRulesListBox.Items[i]).Title != window.Title) 193 if (((Window) windowRulesListBox.Items[i]).Title != window.Title)
202 { 194 {
203 continue; 195 continue;
204 } 196 }
205   197  
206 index = i; 198 index = i;
207 break; 199 break;
208 } 200 }
209   201  
210 if (index == -1) 202 if (index == -1)
211 { 203 {
212 return; 204 return;
213 } 205 }
214   206  
215 windowRulesListBox.Items.RemoveAt(index); 207 windowRulesListBox.Items.RemoveAt(index);
216 Windows.Window.Remove(window); 208 Windows.Window.Remove(window);
217 } 209 }
218   210  
219 private void AddButton_Click(object sender, EventArgs e) 211 private void AddButton_Click(object sender, EventArgs e)
220 { 212 {
221 var window = (Window) desktopWindowsListBox.SelectedItem; 213 var window = (Window) desktopWindowsListBox.SelectedItem;
222 if (window == null) 214 if (window == null)
223 { 215 {
224 return; 216 return;
225 } 217 }
226   218  
227 var found = false; 219 var found = false;
228 foreach (var windowRule in windowRulesListBox.Items) 220 foreach (var windowRule in windowRulesListBox.Items)
229 { 221 {
230 if (((Window) windowRule).Title != window.Title) 222 if (((Window) windowRule).Title != window.Title)
231 { 223 {
232 continue; 224 continue;
233 } 225 }
234   226  
235 found = true; 227 found = true;
236 break; 228 break;
237 } 229 }
238   230  
239 if (found) 231 if (found)
240 { 232 {
241 return; 233 return;
242 } 234 }
243   235  
244 windowRulesListBox.Items.Add(window); 236 windowRulesListBox.Items.Add(window);
245 Windows.Window.Add(window); 237 Windows.Window.Add(window);
246 } 238 }
247   239  
248 private void OnWindowSettings_TextChanged(object sender, EventArgs e) 240 private void OnWindowSettings_TextChanged(object sender, EventArgs e)
249 { 241 {
250 var selectedWindow = (Window) windowRulesListBox.SelectedItem; 242 var selectedWindow = (Window) windowRulesListBox.SelectedItem;
251   243  
252 if (selectedWindow == null) 244 if (selectedWindow == null)
253 { 245 {
254 WindowTitle.Text = string.Empty; 246 WindowTitle.Text = string.Empty;
255 WindowLeft.Text = string.Empty; 247 WindowLeft.Text = string.Empty;
256 WindowTop.Text = string.Empty; 248 WindowTop.Text = string.Empty;
257 WindowWidth.Text = string.Empty; 249 WindowWidth.Text = string.Empty;
258 WindowHeight.Text = string.Empty; 250 WindowHeight.Text = string.Empty;
259   251  
260 return; 252 return;
261 } 253 }
262   254  
263 var textBox = (TextBox) sender; 255 var textBox = (TextBox) sender;
264 switch (textBox.Name) 256 switch (textBox.Name)
265 { 257 {
266 case nameof(WindowTitle): 258 case nameof(WindowTitle):
267 selectedWindow.Title = textBox.Text; 259 selectedWindow.Title = textBox.Text;
268 break; 260 break;
269 case nameof(WindowLeft): 261 case nameof(WindowLeft):
270 if (int.TryParse(textBox.Text, out var left)) 262 if (int.TryParse(textBox.Text, out var left))
271 { 263 {
272 selectedWindow.Left = left; 264 selectedWindow.Left = left;
273 } 265 }
274   266  
275 break; 267 break;
276 case nameof(WindowTop): 268 case nameof(WindowTop):
277 if (int.TryParse(textBox.Text, out var top)) 269 if (int.TryParse(textBox.Text, out var top))
278 { 270 {
279 selectedWindow.Top = top; 271 selectedWindow.Top = top;
280 } 272 }
281   273  
282 break; 274 break;
283 case nameof(WindowWidth): 275 case nameof(WindowWidth):
284 if (int.TryParse(textBox.Text, out var width)) 276 if (int.TryParse(textBox.Text, out var width))
285 { 277 {
286 selectedWindow.Width = width; 278 selectedWindow.Width = width;
287 } 279 }
288   280  
289 break; 281 break;
290 case nameof(WindowHeight): 282 case nameof(WindowHeight):
291 if (int.TryParse(textBox.Text, out var height)) 283 if (int.TryParse(textBox.Text, out var height))
292 { 284 {
293 selectedWindow.Height = height; 285 selectedWindow.Height = height;
294 } 286 }
295   287  
296 break; 288 break;
297 } 289 }
298 } 290 }
299   291  
300 private void OnIgnoreWindowSettings_CheckedChanged(object sender, EventArgs e) 292 private void OnIgnoreWindowSettings_CheckedChanged(object sender, EventArgs e)
301 { 293 {
302 var selectedWindow = (Window) windowRulesListBox.SelectedItem; 294 var selectedWindow = (Window) windowRulesListBox.SelectedItem;
303   295  
304 if (selectedWindow == null) 296 if (selectedWindow == null)
305 { 297 {
306 ignoreLeftCheckBox.Checked = false; 298 ignoreLeftCheckBox.Checked = false;
307 ignoreTopCheckBox.Checked = false; 299 ignoreTopCheckBox.Checked = false;
308 ignoreWidthCheckBox.Checked = false; 300 ignoreWidthCheckBox.Checked = false;
309 ignoreHeightCheckBox.Checked = false; 301 ignoreHeightCheckBox.Checked = false;
310   302  
311 return; 303 return;
312 } 304 }
313   305  
314 var checkBox = (CheckBox) sender; 306 var checkBox = (CheckBox) sender;
315 switch (checkBox.Name) 307 switch (checkBox.Name)
316 { 308 {
317 case nameof(ignoreHeightCheckBox): 309 case nameof(ignoreHeightCheckBox):
318 selectedWindow.IgnoreHeight = checkBox.Checked; 310 selectedWindow.IgnoreHeight = checkBox.Checked;
319 break; 311 break;
320 case nameof(ignoreWidthCheckBox): 312 case nameof(ignoreWidthCheckBox):
321 selectedWindow.IgnoreWidth = checkBox.Checked; 313 selectedWindow.IgnoreWidth = checkBox.Checked;
322 break; 314 break;
323 case nameof(ignoreTopCheckBox): 315 case nameof(ignoreTopCheckBox):
324 selectedWindow.IgnoreTop = checkBox.Checked; 316 selectedWindow.IgnoreTop = checkBox.Checked;
325 break; 317 break;
326 case nameof(ignoreLeftCheckBox): 318 case nameof(ignoreLeftCheckBox):
327 selectedWindow.IgnoreLeft = checkBox.Checked; 319 selectedWindow.IgnoreLeft = checkBox.Checked;
328 break; 320 break;
329 } 321 }
330 } 322 }
331   323  
332 private void DrawButton_Click(object sender, EventArgs e) 324 private void DrawButton_Click(object sender, EventArgs e)
333 { 325 {
334 var selectedWindow = (Window) windowRulesListBox.SelectedItem; 326 var selectedWindow = (Window) windowRulesListBox.SelectedItem;
335 if (selectedWindow == null) 327 if (selectedWindow == null)
336 { 328 {
337 return; 329 return;
338 } 330 }
339   331  
340 if (DrawOverlayForm != null) 332 if (DrawOverlayForm != null)
341 { 333 {
342 return; 334 return;
343 } 335 }
344   336  
345 DrawOverlayForm = new DrawOverlayForm(); 337 DrawOverlayForm = new DrawOverlayForm();
346 DrawOverlayForm.WindowDrawn += DrawOverlayForm_WindowDrawn; 338 DrawOverlayForm.WindowDrawn += DrawOverlayForm_WindowDrawn;
347 DrawOverlayForm.Closed += DrawOverlayForm_Closed; 339 DrawOverlayForm.Closed += DrawOverlayForm_Closed;
348 DrawOverlayForm.Show(); 340 DrawOverlayForm.Show();
349 } 341 }
350   342  
351 private void DrawOverlayForm_WindowDrawn(object sender, WindowDrawnEventArgs e) 343 private void DrawOverlayForm_WindowDrawn(object sender, WindowDrawnEventArgs e)
352 { 344 {
353 var selectedWindow = (Window) windowRulesListBox.SelectedItem; 345 var selectedWindow = (Window) windowRulesListBox.SelectedItem;
354 if (selectedWindow == null) 346 if (selectedWindow == null)
355 { 347 {
356 return; 348 return;
357 } 349 }
358   350  
359 WindowLeft.Text = e.Left.ToString(); 351 WindowLeft.Text = e.Left.ToString();
360 WindowTop.Text = e.Top.ToString(); 352 WindowTop.Text = e.Top.ToString();
361 WindowWidth.Text = e.Width.ToString(); 353 WindowWidth.Text = e.Width.ToString();
362 WindowHeight.Text = e.Height.ToString(); 354 WindowHeight.Text = e.Height.ToString();
363   355  
364 selectedWindow.Left = e.Left; 356 selectedWindow.Left = e.Left;
365 selectedWindow.Top = e.Top; 357 selectedWindow.Top = e.Top;
366 selectedWindow.Width = e.Width; 358 selectedWindow.Width = e.Width;
367 selectedWindow.Height = e.Height; 359 selectedWindow.Height = e.Height;
368 } 360 }
369   361  
370 private void DrawOverlayForm_Closed(object sender, EventArgs e) 362 private void DrawOverlayForm_Closed(object sender, EventArgs e)
371 { 363 {
372 DrawOverlayForm.Closed -= DrawOverlayForm_Closed; 364 DrawOverlayForm.Closed -= DrawOverlayForm_Closed;
373 DrawOverlayForm.WindowDrawn -= DrawOverlayForm_WindowDrawn; 365 DrawOverlayForm.WindowDrawn -= DrawOverlayForm_WindowDrawn;
374 DrawOverlayForm.Dispose(); 366 DrawOverlayForm.Dispose();
375 DrawOverlayForm = null; 367 DrawOverlayForm = null;
376 } 368 }
377   369  
378 private void PickButton_Click(object sender, EventArgs e) 370 private void PickButton_Click(object sender, EventArgs e)
379 { 371 {
380 // Start global mouse key hook. 372 // Start global mouse key hook.
381 GlobalMouseHook = Hook.GlobalEvents(); 373 GlobalMouseHook = Hook.GlobalEvents();
382 GlobalMouseHook.MouseClick += GlobalMouseHook_MouseClick; 374 GlobalMouseHook.MouseClick += GlobalMouseHook_MouseClick;
383   375  
384 // Set cross cursor. 376 // Set cross cursor.
385 foreach (var cursor in Enum.GetValues(typeof(Natives.OCR_SYSTEM_CURSORS))) 377 foreach (var cursor in Enum.GetValues(typeof(Natives.OCR_SYSTEM_CURSORS)))
386 { 378 {
387 Natives.SetSystemCursor( 379 Natives.SetSystemCursor(
388 Natives.CopyIcon(Natives.LoadCursor(IntPtr.Zero, (int) Natives.OCR_SYSTEM_CURSORS.OCR_CROSS)), 380 Natives.CopyIcon(Natives.LoadCursor(IntPtr.Zero, (int) Natives.OCR_SYSTEM_CURSORS.OCR_CROSS)),
389 (uint) cursor); 381 (uint) cursor);
390 } 382 }
391 } 383 }
392   384  
393 private void GlobalMouseHook_MouseClick(object sender, MouseEventArgs e) 385 private void GlobalMouseHook_MouseClick(object sender, MouseEventArgs e)
394 { 386 {
395 var hWnd = Natives.WindowFromPoint(new Point(e.X, e.Y)); 387 var hWnd = Natives.WindowFromPoint(new Point(e.X, e.Y));
396 Natives.GetWindowThreadProcessId(hWnd, out var pid); 388 Natives.GetWindowThreadProcessId(hWnd, out var pid);
397 Process process; 389 Process process;
398 try 390 try
399 { 391 {
400 process = Process.GetProcessById((int) pid); 392 process = Process.GetProcessById((int) pid);
401 } 393 }
402 catch 394 catch
403 { 395 {
404 return; 396 return;
405 } 397 }
406   398  
407 var windowTitle = Helpers.GetWindowTitle(process.MainWindowHandle); 399 var windowTitle = Helpers.GetWindowTitle(process.MainWindowHandle);
408 if (string.IsNullOrEmpty(windowTitle)) 400 if (string.IsNullOrEmpty(windowTitle))
409 { 401 {
410 return; 402 return;
411 } 403 }
412   404  
413 var windowClass = Helpers.GetWindowClass(process.MainWindowHandle); 405 var windowClass = Helpers.GetWindowClass(process.MainWindowHandle);
414 if (string.IsNullOrEmpty(windowClass)) 406 if (string.IsNullOrEmpty(windowClass))
415 { 407 {
416 return; 408 return;
417 } 409 }
418   410  
419 if (!Natives.GetWindowRect(process.MainWindowHandle, out var rect)) 411 if (!Natives.GetWindowRect(process.MainWindowHandle, out var rect))
420 { 412 {
421 return; 413 return;
422 } 414 }
423   415  
424 var window = new Window(windowClass, windowTitle, rect.Top, rect.Left, rect.Right - rect.Left, 416 var window = new Window(windowClass, windowTitle, rect.Top, rect.Left, rect.Right - rect.Left,
425 rect.Bottom - rect.Top); 417 rect.Bottom - rect.Top);
426   418  
427 var found = false; 419 var found = false;
428 foreach (var windowRule in windowRulesListBox.Items) 420 foreach (var windowRule in windowRulesListBox.Items)
429 { 421 {
430 if (((Window) windowRule).Title != window.Title) 422 if (((Window) windowRule).Title != window.Title)
431 { 423 {
432 continue; 424 continue;
433 } 425 }
434   426  
435 found = true; 427 found = true;
436 break; 428 break;
437 } 429 }
438   430  
439 if (found) 431 if (found)
440 { 432 {
441 return; 433 return;
442 } 434 }
443   435  
444 windowRulesListBox.Items.Add(window); 436 windowRulesListBox.Items.Add(window);
445 Windows.Window.Add(window); 437 Windows.Window.Add(window);
446   438  
447 // Revert cursor. 439 // Revert cursor.
448 Natives.SystemParametersInfo(0x0057, 0, null, 0); 440 Natives.SystemParametersInfo(0x0057, 0, null, 0);
449   441  
450 // Remove global mouse key hook. 442 // Remove global mouse key hook.
451 GlobalMouseHook.MouseClick -= GlobalMouseHook_MouseClick; 443 GlobalMouseHook.MouseClick -= GlobalMouseHook_MouseClick;
452 GlobalMouseHook.Dispose(); 444 GlobalMouseHook.Dispose();
453 GlobalMouseHook = null; 445 GlobalMouseHook = null;
454 } 446 }
455   447  
456 #endregion 448 #endregion
457   449  
458 #region Private Methods 450 #region Private Methods
459   451  
460 private void RefreshWindows() 452 private void RefreshWindows()
461 { 453 {
462 foreach (var handle in Helpers.FindWindows((wnd, param) => true)) 454 foreach (var handle in Helpers.FindWindows((wnd, param) => true))
463 { 455 {
464 var windowTitle = Helpers.GetWindowTitle(handle); 456 var windowTitle = Helpers.GetWindowTitle(handle);
465 if (string.IsNullOrEmpty(windowTitle)) 457 if (string.IsNullOrEmpty(windowTitle))
466 { 458 {
467 continue; 459 continue;
468 } 460 }
469   461  
470 var windowClass = Helpers.GetWindowClass(handle); 462 var windowClass = Helpers.GetWindowClass(handle);
471 if (string.IsNullOrEmpty(windowClass)) 463 if (string.IsNullOrEmpty(windowClass))
472 { 464 {
473 continue; 465 continue;
474 } 466 }
475   467  
476 if (!Natives.GetWindowRect(handle, out var rect)) 468 if (!Natives.GetWindowRect(handle, out var rect))
477 { 469 {
478 continue; 470 continue;
479 } 471 }
480   472  
481 var window = new Window(windowClass, windowTitle, rect.Top, rect.Left, rect.Right - rect.Left, 473 var window = new Window(windowClass, windowTitle, rect.Top, rect.Left, rect.Right - rect.Left,
482 rect.Bottom - rect.Top); 474 rect.Bottom - rect.Top);
483   475  
484 this.InvokeIfRequired(form => 476 this.InvokeIfRequired(form =>
485 { 477 {
486 var found = false; 478 var found = false;
487 foreach (var item in desktopWindowsListBox.Items) 479 foreach (var item in desktopWindowsListBox.Items)
488 { 480 {
489 if (((Window) item).Title != window.Title) 481 if (((Window) item).Title != window.Title)
490 { 482 {
491 continue; 483 continue;
492 } 484 }
493   485  
494 found = true; 486 found = true;
495 break; 487 break;
496 } 488 }
497   489  
498 if (!found) 490 if (!found)
499 { 491 {
500 desktopWindowsListBox.Items.Add(window); 492 desktopWindowsListBox.Items.Add(window);
501 } 493 }
502 }); 494 });
503 } 495 }
504 } 496 }
505   497  
506 #endregion 498 #endregion
507 } 499 }
508 } 500 }
509   501  
510
Generated by GNU Enscript 1.6.5.90.
502
Generated by GNU Enscript 1.6.5.90.
511   503  
512   504  
513   505