static void UnsubscribeFromWindowActivationEvents() { if (windowActivationHookHandle == 0) { return; } int result = Win.UnhookWinEvent(windowActivationHookHandle); windowActivationHookHandle = 0; windowActivationDelegate = null; HandleAnyErrors(result); }
static void SubscribeToWindowActivationEvents() { if (windowActivationHookHandle != 0) { return; } windowActivationDelegate = WinEventProc; windowActivationHookHandle = Win.SetWinEventHook(Win.EVENT_SYSTEM_FOREGROUND, Win.EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, windowActivationDelegate, 0, 0, Win.WINEVENT_OUTOFCONTEXT); HandleAnyErrors(windowActivationHookHandle); }