diff --git a/Stealth.Core/WindowInstance/WindowInstanceInfoBase.cs b/Stealth.Core/WindowInstance/WindowInstanceInfoBase.cs index d51522d..54faa13 100644 --- a/Stealth.Core/WindowInstance/WindowInstanceInfoBase.cs +++ b/Stealth.Core/WindowInstance/WindowInstanceInfoBase.cs @@ -35,6 +35,7 @@ public IntPtr hWnd public string windowTitle { get { return _windiwsTitle; } + set { _windiwsTitle = value; } } private bool _isWindowVisible; diff --git a/Stealth.Core/WindowInstance/WindowInstanceInfoDetail.cs b/Stealth.Core/WindowInstance/WindowInstanceInfoDetail.cs index 54ada2e..0ae93d8 100644 --- a/Stealth.Core/WindowInstance/WindowInstanceInfoDetail.cs +++ b/Stealth.Core/WindowInstance/WindowInstanceInfoDetail.cs @@ -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; diff --git a/Stealth.Winform/MainFOrm.Designer.cs b/Stealth.Winform/MainFOrm.Designer.cs index 2a8f3e2..0c2bc10 100644 --- a/Stealth.Winform/MainFOrm.Designer.cs +++ b/Stealth.Winform/MainFOrm.Designer.cs @@ -31,6 +31,8 @@ private void InitializeComponent() this.dataGridView_WindowList = new System.Windows.Forms.DataGridView(); this.hWnd = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Title = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.isModified = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.isRemoved = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.button_Refresh = new System.Windows.Forms.Button(); this.groupBox_WindowDetail = new System.Windows.Forms.GroupBox(); this.tableLayoutPanel_WindowDetail = new System.Windows.Forms.TableLayoutPanel(); @@ -65,7 +67,9 @@ private void InitializeComponent() this.dataGridView_WindowList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView_WindowList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.hWnd, - this.Title}); + this.Title, + this.isModified, + this.isRemoved}); this.tableLayoutPanel_WindowList.SetColumnSpan(this.dataGridView_WindowList, 2); this.dataGridView_WindowList.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGridView_WindowList.Location = new System.Drawing.Point(3, 3); @@ -101,6 +105,26 @@ private void InitializeComponent() this.Title.ReadOnly = true; this.Title.Width = 60; // + // isModified + // + this.isModified.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; + this.isModified.DataPropertyName = "isModified"; + this.isModified.HeaderText = "Modified"; + this.isModified.MinimumWidth = 25; + this.isModified.Name = "isModified"; + this.isModified.ReadOnly = true; + this.isModified.Width = 25; + // + // isRemoved + // + this.isRemoved.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; + this.isRemoved.DataPropertyName = "isRemoved"; + this.isRemoved.HeaderText = "Removed"; + this.isRemoved.MinimumWidth = 25; + this.isRemoved.Name = "isRemoved"; + this.isRemoved.ReadOnly = true; + this.isRemoved.Width = 25; + // // button_Refresh // this.button_Refresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); @@ -331,8 +355,6 @@ private void InitializeComponent() private System.Windows.Forms.Button button_Reset; private System.Windows.Forms.TextBox textBox_Title; private System.Windows.Forms.DataGridView dataGridView_WindowList; - private System.Windows.Forms.DataGridViewTextBoxColumn Title; - private System.Windows.Forms.DataGridViewTextBoxColumn hWnd; private System.Windows.Forms.CheckBox checkBox_Top; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel_WindowDetail; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; @@ -343,6 +365,10 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.TextBox textBox_Filter; + private System.Windows.Forms.DataGridViewCheckBoxColumn isRemoved; + private System.Windows.Forms.DataGridViewCheckBoxColumn isModified; + private System.Windows.Forms.DataGridViewTextBoxColumn Title; + private System.Windows.Forms.DataGridViewTextBoxColumn hWnd; } } diff --git a/Stealth.Winform/MainFOrm.resx b/Stealth.Winform/MainFOrm.resx index 1eee850..df3183b 100644 --- a/Stealth.Winform/MainFOrm.resx +++ b/Stealth.Winform/MainFOrm.resx @@ -123,6 +123,12 @@ True + + True + + + True + 17, 17 diff --git a/Stealth.Winform/MainForm.cs b/Stealth.Winform/MainForm.cs index d21ea39..94e136c 100644 --- a/Stealth.Winform/MainForm.cs +++ b/Stealth.Winform/MainForm.cs @@ -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; @@ -26,12 +27,13 @@ private void FormInit() } private WindowInstanceService windowInstanceService = new WindowInstanceService(); - private List windowInfoList = new List(); + private List windowList = new List(); + private List scanWindowList = new List(); private List filteredWindowList = new List(); private WindowInstanceInfoDetail selectedWindow = null; - #region WindowList + #region WindowList Section private void button_Refresh_Click(object sender, EventArgs e) { @@ -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 windowComparer = new WindowComparer(); + + //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; @@ -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; } @@ -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(); @@ -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 @@ -120,4 +170,18 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e) #endregion } + + public class WindowComparer : IEqualityComparer + where T : WindowInstanceInfoDetail + { + public bool Equals(T x, T y) + { + return x.hWnd == y.hWnd; + } + + public int GetHashCode(T obj) + { + return base.GetHashCode(); + } + } }