Skip to content

Commit

Permalink
Stealth is able to remember each window's status: modified, removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron533 committed Mar 20, 2016
1 parent 61f93dc commit 1ef1c28
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 9 deletions.
1 change: 1 addition & 0 deletions Stealth.Core/WindowInstance/WindowInstanceInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public IntPtr hWnd
public string windowTitle
{
get { return _windiwsTitle; }
set { _windiwsTitle = value; }
}

private bool _isWindowVisible;
Expand Down
3 changes: 3 additions & 0 deletions Stealth.Core/WindowInstance/WindowInstanceInfoDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public bool isTopMost
}
}

public bool isModified { get; set; }
public bool isRemoved { get; set; }

public override string ToString()
{
return base.ToString() + "\n " + transparencyProperty.ToString() + ", isLayered: " +isLayered;
Expand Down
32 changes: 29 additions & 3 deletions Stealth.Winform/MainFOrm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Stealth.Winform/MainFOrm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
<metadata name="Title.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="isModified.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="isRemoved.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
Expand Down
76 changes: 70 additions & 6 deletions Stealth.Winform/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Stealth.Core.Utilities;
using Stealth.Core.WindowInstance;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
Expand All @@ -26,12 +27,13 @@ private void FormInit()
}

private WindowInstanceService windowInstanceService = new WindowInstanceService();
private List<WindowInstanceInfoDetail> windowInfoList = new List<WindowInstanceInfoDetail>();
private List<WindowInstanceInfoDetail> windowList = new List<WindowInstanceInfoDetail>();
private List<WindowInstanceInfoDetail> scanWindowList = new List<WindowInstanceInfoDetail>();
private List<WindowInstanceInfoDetail> filteredWindowList = new List<WindowInstanceInfoDetail>();

private WindowInstanceInfoDetail selectedWindow = null;

#region WindowList
#region WindowList Section

private void button_Refresh_Click(object sender, EventArgs e)
{
Expand All @@ -41,8 +43,36 @@ private void button_Refresh_Click(object sender, EventArgs e)
//refresh the entire the window info list, the filter will be kept
private void RefreshWindowList()
{
windowInfoList = windowInstanceService.GetWindowInstanceInfoDetailList()
scanWindowList = windowInstanceService.GetWindowInstanceInfoDetailList()
.Where(c => c.isWindowVisible && !string.IsNullOrEmpty(c.windowTitle)).ToList();

WindowComparer<WindowInstanceInfoDetail> windowComparer = new WindowComparer<WindowInstanceInfoDetail>();

//check the removed windows
windowList.ForEach(c =>
{
c.isRemoved = !scanWindowList.Contains(c, windowComparer);
});

//add/update scan result to current list
scanWindowList.ForEach(c =>
{
//update
if (windowList.Contains(c, windowComparer))
{
//update
var target = windowList.Where(d => d.hWnd == c.hWnd).FirstOrDefault();
bool isModified = target.isModified;
target = c;
target.isModified = isModified;
}
//add
else
{
windowList.Add(c);
}
});

dataGridView_WindowList.AutoGenerateColumns = false;
WindowListFilter();
//dataGridView_WindowList.DataSource = windowInfoList;
Expand All @@ -51,7 +81,7 @@ private void RefreshWindowList()
//realtime window filter: by Title name
private void WindowListFilter()
{
filteredWindowList = windowInfoList.Where(c => c.windowTitle.ToLower().Contains(textBox_Filter.Text.ToLower())).ToList();
filteredWindowList = windowList.Where(c => c.windowTitle.ToLower().Contains(textBox_Filter.Text.ToLower())).ToList();
dataGridView_WindowList.DataSource = filteredWindowList;
}

Expand All @@ -64,13 +94,32 @@ private void textBox_Filter_TextChanged(object sender, EventArgs e)
//when user select a row
private void dataGridView_WindowList_RowEnter(object sender, DataGridViewCellEventArgs e)
{
selectedWindow = filteredWindowList[e.RowIndex];
selectedWindow = windowList.Find(c => c.hWnd == filteredWindowList[e.RowIndex].hWnd);
textBox_Title.Text = selectedWindow.windowTitle;
if (selectedWindow.isModified)
{
trackBar_Trans.Value = selectedWindow.transparencyProperty.bAlpha;
}
else
{
trackBar_Trans.Value = trackBar_Trans.Maximum;
}
}

//style
DataGridViewCellStyle isRemovedStyle = new DataGridViewCellStyle()
{
ForeColor = Color.Gray
};

DataGridViewCellStyle isModifiedStyle = new DataGridViewCellStyle()
{
BackColor = Color.LightYellow
};

#endregion

#region WindowDetail
#region WindowDetail Section
private void trackBar_Trans_Scroll(object sender, EventArgs e)
{
UpdateTransLabel();
Expand Down Expand Up @@ -101,6 +150,7 @@ private void SetWindow()
selectedWindow.isLayered = true;
selectedWindow.transparencyProperty.bAlpha = (byte)trackBar_Trans.Value;
selectedWindow.transparencyProperty.dwFlags = (uint)User32.LWA.LWA_ALPHA;
selectedWindow.isModified = true;
}

#endregion
Expand All @@ -120,4 +170,18 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
#endregion

}

public class WindowComparer<T> : IEqualityComparer<T>
where T : WindowInstanceInfoDetail
{
public bool Equals(T x, T y)
{
return x.hWnd == y.hWnd;
}

public int GetHashCode(T obj)
{
return base.GetHashCode();
}
}
}

0 comments on commit 1ef1c28

Please sign in to comment.