/// <summary> /// Start dialog box interception for the specified owner window /// </summary> /// <param name="owner_window">owner window, if it is IntPtr.Zero then any windows will be intercepted</param> /// <param name="process_window">custom delegate to process intercepted window. It should be a fast code in order to have no message stack overflow.</param> public WindowInterceptor(IntPtr hMod, uint threadID) { hookProcedure = new Functions.HookProc(HookProcedure); //hook_id = Win32.Functions.SetWindowsHookEx(Win32.HookType.WH_CALLWNDPROCRET, cbf, IntPtr.Zero, Win32.Functions.GetCurrentThreadId()); hook_id = Win32.Functions.SetWindowsHookEx(Win32.HookType.WH_CALLWNDPROCRET, hookProcedure, hMod, threadID); errorCode = Marshal.GetLastWin32Error(); }
/// <summary> /// Start dialog box interception for the specified owner window /// </summary> /// <param name="owner_window">owner window, if it is IntPtr.Zero then any windows will be intercepted</param> /// <param name="process_window">custom delegate to process intercepted window. It should be a fast code in order to have no message stack overflow.</param> public WindowInterceptor(IntPtr owner_window, ProcessWindow process_window) { if (process_window == null) { throw new Exception("process_window cannot be null!"); } this.process_window = process_window; this.owner_window = owner_window; cbf = new Functions.HookProc(dlg_box_hook_proc); //notice that win32 callback function must be a global variable within class to avoid disposing it! hook_id = Functions.SetWindowsHookEx(HookType.WH_CALLWNDPROCRET, cbf, IntPtr.Zero, Functions.GetCurrentThreadId()); }
public static extern IntPtr SetWindowsHookEx(HookType hook, Functions.HookProc callback, IntPtr hMod, uint dwThreadId);