Skip to content

Commit

Permalink
Unique ETW session name & better ListView column handling
Browse files Browse the repository at this point in the history
  • Loading branch information
creizlein committed Aug 10, 2023
1 parent e70cbb8 commit 7adc675
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Classes/Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public static bool AddPrivilege(string privilege) {
}
}

[SupportedOSPlatform("windows")]
internal class CpuUsage {
private API.FILETIME _idleTime, _kernTime, _userTime;
private long _oldCpuUsage = 0, _oldKernUsage = 0, _oldUserUsage = 0;
Expand Down
24 changes: 20 additions & 4 deletions src/Controls/sMkListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using static sMkTaskManager.Controls.sMkListViewHelpers;
Expand Down Expand Up @@ -234,7 +235,7 @@ private void OnDataSource_ListChanged(object? sender, ListChangedEventArgs e) {
switch (e.ListChangedType) {
case ListChangedType.ItemAdded: OnDataSource_RowAdded(e); break;
case ListChangedType.ItemChanged: OnDataSource_RowChanged(e); break;
// case ListChangedType.ItemDeleted: OnDataSource_RowDeleted(e); break;
// case ListChangedType.ItemDeleted: OnDataSource_RowDeleted(e); break;
}
}
private void OnDataSource_RowAdded(ListChangedEventArgs e) {
Expand All @@ -249,6 +250,7 @@ private void OnDataSource_RowAdded(ListChangedEventArgs e) {
if (d.Name == "BackColor") { itm.BackColor = (Color)d.GetValue(row)!; }
if ((d.Name == "ImageKey") && ((string?)d.GetValue(row) != "")) { itm.ImageKey = (string)d.GetValue(row)!; }
if ((d.Name == "ImageIndex") && ((int?)d.GetValue(row) > -1)) { itm.ImageIndex = (int)d.GetValue(row)!; }
if ((d.Name == "StateImageIndex") && ((int?)d.GetValue(row) > -1)) { itm.StateImageIndex = (int)d.GetValue(row)!; }
}
// Populate each value of the item if the column exists.
foreach (ColumnHeader c in Columns) {
Expand Down Expand Up @@ -297,6 +299,12 @@ private void OnDataSource_RowChanged(ListChangedEventArgs e) {
Items[_keyDescriptor.GetValue(row)!.ToString()].ImageIndex = (int)e.PropertyDescriptor.GetValue(row)!;
}
return;
case "StateImageIndex": // Set The Image Index
if (Items.ContainsKey(_keyDescriptor.GetValue(row)!.ToString())) {
Items[_keyDescriptor.GetValue(row)!.ToString()].StateImageIndex = (int)e.PropertyDescriptor.GetValue(row)!;
}
return;

default: // Set Values...
foreach (ColumnHeader c in Columns) {
if (e.PropertyDescriptor?.Name.ToLower() == c.Tag?.ToString()?.ToLower()) {
Expand Down Expand Up @@ -348,7 +356,13 @@ public void SetColumns(in ListViewItemCollection colItems) {
}
EndUpdate();
}

public int TotalColumnsWidth(int exceptColumn) {
int res = 0;
for (int i = 0; i < Columns.Count; i++) {
if (i != exceptColumn) res += Columns[i].Width;
}
return res;
}
}

public static class sMkListViewHelpers {
Expand All @@ -373,9 +387,11 @@ public struct HDITEM {
public int iImage;
public int iOrder;
}
[System.Security.SuppressUnmanagedCodeSecurity()] [DllImport("USER32.DLL", EntryPoint = "SendMessage")]
[System.Security.SuppressUnmanagedCodeSecurity()]
[DllImport("USER32.DLL", EntryPoint = "SendMessage")]
public static unsafe extern IntPtr GetHeaderHnd(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[System.Security.SuppressUnmanagedCodeSecurity()] [DllImport("USER32.DLL", EntryPoint = "SendMessage")]
[System.Security.SuppressUnmanagedCodeSecurity()]
[DllImport("USER32.DLL", EntryPoint = "SendMessage")]
public static unsafe extern IntPtr SendMessageItem(IntPtr Handle, int msg, IntPtr wParam, ref HDITEM lParam);

}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/frmColumns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public frmColumns(TaskManagerColumnTypes Type) : this() {

private void frmColumns_Load(object sender, EventArgs e) {
lv.Columns[0].Width = -2;
lv.Columns[0].Width -= 5;
lv.Columns[0].Width -= (SystemInformation.VerticalScrollBarWidth+2);
}
private void btnOk_Click(object sender, EventArgs e) {
DialogResult = DialogResult.OK;
Expand Down
3 changes: 2 additions & 1 deletion src/Forms/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ private void OnLoadParallelInit(object? sender, DoWorkEventArgs e) {
Stopwatch sw = new();
Extensions.StartMeasure(sw);
// We should use this to initialize something that is not really critical?
Shared.ETW.Start();
if (Shared.PrivateMsgID == 0) Shared.PrivateMsgID = API.RegisterWindowMessage(Application.ExecutablePath.Replace("\\", "_"));
Shared.ETW.sessionName += "-" + Shared.PrivateMsgID;
Shared.ETW.Start();
// if (Shared.AddPrivilege("SeDebugPrivilege")) Debug.WriteLine("SeDebugPrivilege Set");
Shared.InitComplete = true;
MonitorStart(true);
Expand Down
10 changes: 5 additions & 5 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
[assembly: AssemblyConfiguration("Release")]
#endif

[assembly: AssemblyVersion("3.0.25.*")]
[assembly: AssemblyFileVersion("3.0.25")]
[assembly: AssemblyInformationalVersion("3.0.25")]
[assembly: GitCommit("gaf30a6a869b917296b34c552c8d229dc8c605f61")]
[assembly: BuildMark("1690083951")]
[assembly: AssemblyVersion("3.0.30.*")]
[assembly: AssemblyFileVersion("3.0.30")]
[assembly: AssemblyInformationalVersion("3.0.30")]
[assembly: GitCommit("gad32159dda4b9258bcd5de2dcb81f20b782899a0")]
[assembly: BuildMark("1691689894")]

0 comments on commit 7adc675

Please sign in to comment.