internal override void Start(IWinMessageFilter filter) { if (_dispatcher == null) { // using this hack so the new thread will start running before this function returns using (var hack = new WrappedManualResetEvent()) { var loopThread = new Thread(new ThreadStart(() => { PlatformInfo.Current.Log.Debug("NTwain internal message loop is starting."); _dispatcher = Dispatcher.CurrentDispatcher; if (!PlatformInfo.Current.IsOnMono) { _hook = new WindowsHook(filter); Handle = _hook.Handle; } hack.Set(); Dispatcher.Run(); // if dispatcher shutsdown we'll get here so make everything uninitialized _dispatcher = null; if (_hook != null) { _hook.Dispose(); _hook = null; Handle = IntPtr.Zero; } })); loopThread.IsBackground = true; loopThread.SetApartmentState(ApartmentState.STA); loopThread.Start(); hack.Wait(); } } }
public WindowsHook(IWinMessageFilter filter) { _filter = filter; HwndSource win = null; try { // hook into windows msg loop for old twain to post msgs. // the style values are purely guesses here with // CS_NOCLOSE, WS_TILEDWINDOW, and WS_EX_APPWINDOW win = new HwndSource(0x0200, 0xCF0000, 0x40000, 0, 0, "NTWAIN_LOOPER", IntPtr.Zero); Handle = win.Handle; win.AddHook(WndProc); _win = win; } catch { if (win != null) { win.Dispose(); } throw; } }
internal override void Stop() { //Invoke(() => //{ System.Windows.Forms.Application.RemoveMessageFilter(this); _filter = null; //}); }
internal override void Start(IWinMessageFilter filter) { //Invoke(() => //{ _filter = filter; System.Windows.Forms.Application.AddMessageFilter(this); //}); }
internal override void Start(IWinMessageFilter filter) { _filter = filter; _hooker = HwndSource.FromHwnd(Handle); _hooker.AddHook(FilterMessage); }
internal abstract void Start(IWinMessageFilter filter);