public static void StartMonitoringActiveAppChangesIfNeeded() { if (ShouldMonitorActiveAppChange() && CurrentHook == IntPtr.Zero) { _handler = new WinEventHookProc(OnActiveWindowChanged); CurrentHook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, _handler, 0, 0, WINEVENT_OUTOFCONTEXT); } }
static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventHookProc lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);