1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-25 15:20:10 +00:00
msfs-popout-panel-manager/WindowsAgent/WindowProcessManager.cs

58 lines
1.7 KiB
C#
Raw Normal View History

2022-07-23 19:23:32 +00:00
using System;
2022-01-27 13:40:04 +00:00
using System.Diagnostics;
2022-07-23 19:23:32 +00:00
namespace MSFSPopoutPanelManager.WindowsAgent
2022-01-27 13:40:04 +00:00
{
2022-07-23 19:23:32 +00:00
public class WindowProcessManager
2022-01-27 13:40:04 +00:00
{
public static string GetApplicationVersion()
{
var systemAssemblyVersion = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
var appVersion = $"{systemAssemblyVersion.Major}.{systemAssemblyVersion.Minor}.{systemAssemblyVersion.Build}";
2022-10-11 13:37:49 +00:00
if (systemAssemblyVersion.Revision > 0)
appVersion += "." + systemAssemblyVersion.Revision.ToString("D4");
2022-01-27 13:40:04 +00:00
return appVersion;
}
2023-07-12 22:41:31 +00:00
public static WindowProcess SimulatorProcess { get; private set; }
public static void GetSimulatorProcess()
2022-01-27 13:40:04 +00:00
{
2023-07-12 22:41:31 +00:00
SimulatorProcess = GetWindowProcess("FlightSimulator");
2022-01-27 13:40:04 +00:00
}
public static WindowProcess GetApplicationProcess()
{
2022-07-23 19:23:32 +00:00
return GetWindowProcess("MSFSPopoutPanelManager");
2022-01-27 13:40:04 +00:00
}
2022-07-23 19:23:32 +00:00
private static WindowProcess GetWindowProcess(string processName)
2022-01-27 13:40:04 +00:00
{
foreach (var process in Process.GetProcesses())
{
if (process.ProcessName == processName)
{
return new WindowProcess()
{
ProcessId = process.Id,
ProcessName = process.ProcessName,
2022-08-08 06:07:24 +00:00
Handle = process.MainWindowHandle
2022-01-27 13:40:04 +00:00
};
}
}
return null;
}
}
2022-07-23 19:23:32 +00:00
public class WindowProcess
{
public int ProcessId { get; set; }
public string ProcessName { get; set; }
public IntPtr Handle { get; set; }
}
2022-01-27 13:40:04 +00:00
}