/trunk/Widow/RuleEditForm.cs |
@@ -1,5 +1,6 @@ |
using System; |
using System.Collections.Generic; |
using System.Threading.Tasks; |
using System.Windows.Forms; |
using Windows; |
|
@@ -39,10 +40,12 @@ |
{ |
InitializeComponent(); |
|
desktopWindowsListBox.DisplayMember = "Name"; |
windowRulesListBox.DisplayMember = "Name"; |
desktopWindowsListBox.DisplayMember = nameof(Window.Title); |
desktopWindowsListBox.SetDoubleBuffered(); |
windowRulesListBox.DisplayMember = nameof(Window.Title); |
windowRulesListBox.SetDoubleBuffered(); |
|
RefreshWindows(); |
Task.Run(RefreshWindows); |
} |
|
/// <summary> |
@@ -68,7 +71,7 @@ |
|
private void Form_WindowDestroyed(object sender, WindowDestroyedEventArgs e) |
{ |
if (string.IsNullOrEmpty(e.Name)) |
if (string.IsNullOrEmpty(e.Title)) |
{ |
return; |
} |
@@ -76,7 +79,7 @@ |
var indices = new List<int>(); |
for (var i = 0; i < desktopWindowsListBox.Items.Count; ++i) |
{ |
if (((Window) desktopWindowsListBox.Items[i]).Name == e.Name) |
if (((Window) desktopWindowsListBox.Items[i]).Title == e.Title) |
{ |
indices.Add(i); |
} |
@@ -90,7 +93,7 @@ |
|
private void Form_WindowCreated(object sender, WindowCreatedEventArgs e) |
{ |
if (string.IsNullOrEmpty(e.Name)) |
if (string.IsNullOrEmpty(e.Title)) |
{ |
return; |
} |
@@ -98,7 +101,7 @@ |
var found = false; |
foreach (var window in desktopWindowsListBox.Items) |
{ |
if (((Window) window).Name == e.Name) |
if (((Window) window).Title == e.Title) |
{ |
found = true; |
break; |
@@ -110,13 +113,21 @@ |
return; |
} |
|
if (Natives.GetWindowRect(e.Handle, out var rect)) |
if (!Natives.GetWindowRect(e.Handle, out var rect)) |
{ |
var window = new Window(e.Name, rect.Top, rect.Left, rect.Right - rect.Left, |
rect.Bottom - rect.Top); |
return; |
} |
|
desktopWindowsListBox.Items.Add(window); |
var process = Helpers.GetProcessName(e.Handle); |
if (string.IsNullOrEmpty(process)) |
{ |
return; |
} |
|
var newWindow = new Window(process, e.Title, rect.Top, rect.Left, rect.Right - rect.Left, |
rect.Bottom - rect.Top); |
|
desktopWindowsListBox.Items.Add(newWindow); |
} |
|
private void WindowRulesListBox_SelectedIndexChanged(object sender, EventArgs e) |
@@ -125,7 +136,7 @@ |
|
if (listBox.SelectedIndex == -1) |
{ |
WindowName.Text = string.Empty; |
WindowTitle.Text = string.Empty; |
ignoreLeftCheckBox.Checked = false; |
WindowLeft.Text = string.Empty; |
ignoreTopCheckBox.Checked = false; |
@@ -144,7 +155,7 @@ |
return; |
} |
|
WindowName.Text = window.Name; |
WindowTitle.Text = window.Title; |
ignoreLeftCheckBox.Checked = window.IgnoreLeft; |
WindowLeft.Text = window.Left.ToString(); |
ignoreTopCheckBox.Checked = window.IgnoreTop; |
@@ -157,7 +168,7 @@ |
|
private void RefreshButton_Click(object sender, EventArgs e) |
{ |
RefreshWindows(); |
Task.Run(RefreshWindows); |
} |
|
private void RemoveButton_Click(object sender, EventArgs e) |
@@ -171,11 +182,13 @@ |
var index = -1; |
for (var i = 0; i < windowRulesListBox.Items.Count; ++i) |
{ |
if (((Window) windowRulesListBox.Items[i]).Name == window.Name) |
if (((Window) windowRulesListBox.Items[i]).Title != window.Title) |
{ |
index = i; |
break; |
continue; |
} |
|
index = i; |
break; |
} |
|
if (index == -1) |
@@ -198,11 +211,13 @@ |
var found = false; |
foreach (var windowRule in windowRulesListBox.Items) |
{ |
if (((Window) windowRule).Name == window.Name) |
if (((Window) windowRule).Title != window.Title) |
{ |
found = true; |
break; |
continue; |
} |
|
found = true; |
break; |
} |
|
if (found) |
@@ -220,7 +235,7 @@ |
|
if (selectedWindow == null) |
{ |
WindowName.Text = string.Empty; |
WindowTitle.Text = string.Empty; |
WindowLeft.Text = string.Empty; |
WindowTop.Text = string.Empty; |
WindowWidth.Text = string.Empty; |
@@ -232,8 +247,8 @@ |
var textBox = (TextBox) sender; |
switch (textBox.Name) |
{ |
case nameof(WindowName): |
selectedWindow.Name = textBox.Text; |
case nameof(WindowTitle): |
selectedWindow.Title = textBox.Text; |
break; |
case nameof(WindowLeft): |
if (int.TryParse(textBox.Text, out var left)) |
@@ -304,26 +319,40 @@ |
|
private void RefreshWindows() |
{ |
foreach (var desktopWindow in Helpers.GetDesktopWindows()) |
foreach (var handle in Helpers.FindWindows((wnd, param) => true)) |
{ |
if (string.IsNullOrEmpty(desktopWindow.Title)) |
var title = Helpers.GetWindowTitle(handle); |
if (string.IsNullOrEmpty(title)) |
{ |
continue; |
} |
|
if (Natives.GetWindowRect(desktopWindow.Handle, out var rect)) |
var process = Helpers.GetProcessName(handle); |
if (string.IsNullOrEmpty(process)) |
{ |
var window = new Window(desktopWindow.Title, rect.Top, rect.Left, rect.Right - rect.Left, |
rect.Bottom - rect.Top); |
continue; |
} |
|
if (!Natives.GetWindowRect(handle, out var rect)) |
{ |
continue; |
} |
|
var window = new Window(process, title, rect.Top, rect.Left, rect.Right - rect.Left, |
rect.Bottom - rect.Top); |
|
this.Execute(() => |
{ |
var found = false; |
foreach (var item in desktopWindowsListBox.Items) |
{ |
if (((Window) item).Name == window.Name) |
if (((Window) item).Title != window.Title) |
{ |
found = true; |
break; |
continue; |
} |
|
found = true; |
break; |
} |
|
if (!found) |
@@ -330,7 +359,7 @@ |
{ |
desktopWindowsListBox.Items.Add(window); |
} |
} |
}); |
} |
} |
|