public CurrentProcessService() { _delegate = new Win32.WinEventDelegate(WinEventProc); _hook = Win32.SetWinEventHook(Win32.EVENT_SYSTEM_FOREGROUND, Win32.EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, _delegate, 0, 0, Win32.WINEVENT_OUTOFCONTEXT); _cts = new CancellationTokenSource(); _processEventAdded = new AsyncAutoResetEvent(); _notifyArgs = new ConcurrentQueue <ProcessEventArgs>(); _notifyTask = NotifyCycle(_cts.Token); }
private void RegisterHooks() { Win32.WinEventDelegate dele = WinEventProc; _delegateHandle = GCHandle.Alloc(dele); const uint flags = Win32.WINEVENT_OUTOFCONTEXT | Win32.WINEVENT_SKIPOWNPROCESS | Win32.WINEVENT_SKIPOWNTHREAD; _hooks.Add(Win32.SetWinEventHook(Win32.EVENT_SYSTEM_FOREGROUND, Win32.EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, dele, 0, 0, flags)); _hooks.Add(Win32.SetWinEventHook(Win32.EVENT_OBJECT_CREATE, Win32.EVENT_OBJECT_DESTROY, IntPtr.Zero, dele, 0, 0, flags)); _hooks.Add(Win32.SetWinEventHook(Win32.EVENT_SYSTEM_MOVESIZEEND, Win32.EVENT_SYSTEM_MOVESIZEEND, IntPtr.Zero, dele, 0, 0, flags)); _hooks.Add(Win32.SetWinEventHook(Win32.EVENT_SYSTEM_MINIMIZESTART, Win32.EVENT_SYSTEM_MINIMIZEEND, IntPtr.Zero, dele, 0, 0, flags)); }
/// <summary> /// Create a window hook manager and start listening for events /// </summary> public WindowHookManager() { Win32.WinEventDelegate hookDelegate = WinEventProc; _focusedChangedEventPin = GCHandle.Alloc(WindowFocusChanged); _hookDelegatePin = GCHandle.Alloc(hookDelegate); _ownProcessId = Process.GetCurrentProcess().Id; _windowsEventsHook = Win32.SetWinEventHook( Win32.EVENT_MIN, Win32.EVENT_MAX, // give me all the events. This may cause slow-down... IntPtr.Zero, hookDelegate, 0, 0, // all processes and threads Win32.WINEVENT_OUTOFCONTEXT | Win32.WINEVENT_SKIPOWNPROCESS); // only other processes }
public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // Register an event hook with Windows SDK to get notified when the foreground window changes - // i.e. when you activate a new window. We also have a timer that will check every few hundred // milliseconds, but this is more responsive. // // N.B. I tried registering a hook for EVENT_OBJECT_LOCATIONCHANGE events too, but it gave loads // of firings when you just move the mouse and didn't actually fire when you move the window. // I also tried EVENT_SYSTEM_MOVESIZEEND but it didn't work. // hook_i = new Win32.WinEventDelegate(WinEventProc); Win32.SetWinEventHook(Win32.EVENT_SYSTEM_FOREGROUND, Win32.EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, hook_i, 0, 0, Win32.WINEVENT_OUTOFCONTEXT); // // Make it display properly on startup // HandleWindowActivation(Win32.GetForegroundWindow()); }
public WindowStickHook(IntPtr handle, IStickPointProvider pointProvider) { this.handle = handle; this.pointProvider = pointProvider; this.hookDelegate = new Win32.WinEventDelegate(WndProc2); }
/// <summary> /// With this class you are able to listen to global window event(s). /// </summary> /// <param name="winEvent"><see cref="WINEVENT"/></param> /// <param name="dwFlags"><see cref="WINEVENT.WINEVENT_OUTOFCONTEXT"/> | <see cref="WINEVENT.WINEVENT_SKIPOWNPROCESS"/></param> public WindowEventListener(uint winEvent, uint dwFlags) { win32EventHandler = new Win32.WinEventDelegate(desktop_win32EventRaised); hookId = Win32.SetWinEventHook(winEvent, winEvent, IntPtr.Zero, win32EventHandler, 0, 0, dwFlags); }
public ApplicationManipulator() { dele = new Win32.WinEventDelegate(WinEventProc); IntPtr m_hhook = Win32.SetWinEventHook(Win32.EVENT_SYSTEM_FOREGROUND, Win32.EVENT_SYSTEM_FOREGROUND, IntPtr.Zero, dele, 0, 0, Win32.WINEVENT_OUTOFCONTEXT); }