private ForegroundItem GetForeground() { StringBuilder Buff = new StringBuilder(ForegroundItem.WINDOW_TITLE_LENGTH); IntPtr handle = GetForegroundWindow(); GetWindowThreadProcessId(handle, out uint pid); Process p = Process.GetProcessById((int)pid); string processName = p.ProcessName; string executableName = p.MainModule.FileName; string windowTitle = GetWindowText(handle, Buff, ForegroundItem.WINDOW_TITLE_LENGTH) > 0 ? Buff.ToString() : ""; var foreground = new ForegroundItem(executableName, processName, windowTitle); return(foreground); }
public void SendForegroundItem(ForegroundItem item) { string json = JsonSerializer.Serialize(item); client.Send(json); }