IntPtr SetHook(EnumWindowEvent @event) { IntPtr hookId = DllUser32.SetWinEventHook( hookMin: @event, hookMax: @event, moduleHandle: IntPtr.Zero, callback: _eventProc, processId: 0, threadId: 0, flags: EnumHookFlags.OUT_OF_CONTEXT); if (hookId == IntPtr.Zero) { throw new Win32Exception(); } return(hookId); }