Skip to content

Commit

Permalink
Update Program.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
valloon427428 committed Jan 30, 2024
1 parent 5d9c698 commit 90869c4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ActiveProcess/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ internal class Program
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);

public static (IntPtr handle, uint pid, string windowTitle, string windowClass, string processName, string Filename) GetActiveProcessInfo()
public static (IntPtr handle, uint pid, string windowTitle, string windowClass, string processName, string filename) GetActiveProcessInfo()
{
IntPtr handle = default;
uint pid = 0;
string windowTitle = null, windowClass = null, processName = null, Filename = null;
string windowTitle = null, windowClass = null, processName = null, filename = null;
try
{
handle = GetForegroundWindow();
Expand Down Expand Up @@ -61,7 +61,7 @@ public static (IntPtr handle, uint pid, string windowTitle, string windowClass,
GetWindowThreadProcessId(handle, out pid);
Process p = Process.GetProcessById((int)pid);
processName = p.ProcessName;
Filename = p.GetMainModuleFileName();
filename = p.GetMainModuleFileName();
}
catch (Exception ex)
{
Expand All @@ -73,7 +73,7 @@ public static (IntPtr handle, uint pid, string windowTitle, string windowClass,
{
Console.WriteLine(ex);
}
return (handle, pid, windowTitle, windowClass, processName, Filename);
return (handle, pid, windowTitle, windowClass, processName, filename);
}

static void Main(string[] args)
Expand All @@ -84,8 +84,8 @@ static void Main(string[] args)
{
Thread.Sleep(1000);
loop++;
(var handle, var pid, var windowTitle, var windowClass, var processName, var Filename) = GetActiveProcessInfo();
var printText = $"Handle = {handle}\nPID = {pid}\nWindowTitle = \"{windowTitle ?? "null"}\"/{windowTitle?.Length}\nWindowClass = \"{windowClass ?? "null"}\"/{windowClass?.Length}\nProcessName = {processName ?? "null"}\"/{processName?.Length}\nFilename = \"{Filename ?? "null"}\"/{Filename?.Length}\n";
(var handle, var pid, var windowTitle, var windowClass, var processName, var filename) = GetActiveProcessInfo();
var printText = $"Handle = {handle}\nPID = {pid}\nWindowTitle = \"{windowTitle ?? "null"}\"/{windowTitle?.Length}\nWindowClass = \"{windowClass ?? "null"}\"/{windowClass?.Length}\nProcessName = {processName ?? "null"}\"/{processName?.Length}\nFilename = \"{filename ?? "null"}\"/{filename?.Length}\n";
if (lastText != printText)
{
lastText = printText;
Expand Down

0 comments on commit 90869c4

Please sign in to comment.