public static string GetActiveWindowTitle() { const int nChars = 256; StringBuilder stringBuilder = new StringBuilder(nChars); IntPtr foregroundWindowHandle = Win.GetForegroundWindow(); if (Win.GetWindowText(foregroundWindowHandle, stringBuilder, Win.GetWindowTextLength(foregroundWindowHandle) + 1) > 0) { return(stringBuilder.ToString()); } return(null); }
public static void Start() { if (StepDiagram != null) { throw new Exception("Unable to start twice. Already listening. Call HookEngine.Stop after calling HookEngine.Start"); } activeWindowHandle = Win.GetActiveWindow(); StepDiagram = new StepDiagram(); cpuUsageCalculator = new CpuUsageCalculator(); currentProcessTimer = new Timer(CheckCpuUsage, null, 100, 100); HookEvents(); StepDiagram.AddTaskActive(WindowsEvents.GetActiveWindowTitle(), Win.GetForegroundWindow()); }