internal WindowTrigger(ActionTriggers triggers, Action <WindowTriggerArgs> action, TWEvent ev, AWnd.Finder finder, TWFlags flags, TWLater later) : base(triggers, action, false) { this.ev = ev; this.finder = finder; this.flags = flags; this.later = later; }
public static extern ReturnCode DsmWinNew( [In, Out] TWIdentity origin, [In, Out] TWIdentity destination, DataGroups dg, DataArgumentType dat, Message msg, [In, Out] TWEvent data);
/// <summary> /// Adds a window trigger and its action. /// </summary> /// <exception cref="InvalidOperationException">Cannot add triggers after <c>Triggers.Run</c> was called, until it returns.</exception> public Action <WindowTriggerArgs> this[TWEvent winEvent, AWnd.Finder f, TWFlags flags = 0, TWLater later = 0] { set { _triggers.ThrowIfRunning_(); if (f.Props.contains.Value is AWinImage.Finder) { AWarning.Write("Window triggers with 'contains image' are unreliable."); } var t = new WindowTrigger(_triggers, value, winEvent, f, flags, later); ref var last = ref _tActive; if (t.IsVisible)
/// <summary> /// Adds a window trigger and its action. /// </summary> /// <param name="winEvent">Trigger event.</param> /// <param name="name">See <see cref="AWnd.Find"/>.</param> /// <param name="cn">See <see cref="AWnd.Find"/>.</param> /// <param name="of">See <see cref="AWnd.Find"/>.</param> /// <param name="also">See <see cref="AWnd.Find"/>.</param> /// <param name="contains">See <see cref="AWnd.Find"/>.</param> /// <param name="flags">Trigger flags.</param> /// <param name="later"> /// Can optionally specify one or more additional events. /// This starts to work when the primary trigger is activated, and works only for that window. /// For example, to be notified when the window is closed or renamed, specify <c>later: TWLater.Destroyed | TWLater.Name</c>. /// When a "later" event occurs, the trigger action is executed. The <see cref="WindowTriggerArgs.Later"/> property then is that event; it is 0 when it is the primary trigger. /// The "later" trigers are not disabled when primary triggers are disabled. /// </param> /// <exception cref="InvalidOperationException">Cannot add triggers after <c>Triggers.Run</c> was called, until it returns.</exception> /// <exception cref="ArgumentException">See <see cref="AWnd.Find"/>.</exception> /// <seealso cref="Last"/> public Action <WindowTriggerArgs> this[TWEvent winEvent, [ParamString(PSFormat.AWildex)] string name = null, [ParamString(PSFormat.AWildex)] string cn = null, [ParamString(PSFormat.AWildex)] WOwner of = default, Func <AWnd, bool> also = null, WContains contains = default, TWFlags flags = 0, TWLater later = 0 ] { set { var f = new AWnd.Finder(name, cn, of, 0, also, contains); this[winEvent, f, flags, later] = value; } }
public static ReturnCode DsmEntry( TWIdentity origin, TWIdentity destination, Message msg, TWEvent data) { if (PlatformInfo.Current.IsWindows) { if (PlatformInfo.Current.UseNewWinDSM) { return(NativeMethods.DsmWinNew(origin, destination, DataGroups.Control, DataArgumentType.Event, msg, data)); } else { return(NativeMethods.DsmWinOld(origin, destination, DataGroups.Control, DataArgumentType.Event, msg, data)); } } else if (PlatformInfo.Current.IsLinux) { return(NativeMethods.DsmLinux(origin, destination, DataGroups.Control, DataArgumentType.Event, msg, data)); } throw new PlatformNotSupportedException(); }
/// <summary> /// Checks and handles the message if it's a TWAIN message. /// </summary> /// <param name="hwnd">The window handle.</param> /// <param name="msg">The message.</param> /// <param name="wParam">The w parameter.</param> /// <param name="lParam">The l parameter.</param> /// <returns> /// true if handled internally. /// </returns> public bool IsTwainMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam) { bool handled = false; // this handles the message from a typical WndProc message loop and check if it's from the TWAIN source. if (_state >= 5) { // transform it into a pointer for twain IntPtr msgPtr = IntPtr.Zero; try { var winMsg = new MESSAGE(hwnd, msg, wParam, lParam); // no need to do another lock call when using marshal alloc msgPtr = Marshal.AllocHGlobal(Marshal.SizeOf(winMsg)); Marshal.StructureToPtr(winMsg, msgPtr, false); var evt = new TWEvent(); evt.pEvent = msgPtr; if (handled = (((ITwainSessionInternal)this).DGControl.Event.ProcessEvent(evt) == ReturnCode.DSEvent)) { PlatformInfo.Current.Log.Debug("Thread {0}: HandleWndProcMessage at state {1} with MSG={2}.", Thread.CurrentThread.ManagedThreadId, State, evt.TWMessage); HandleSourceMsg(evt.TWMessage); } } finally { if (msgPtr != IntPtr.Zero) { Marshal.FreeHGlobal(msgPtr); } } } return(handled); }
/// <summary> /// This operation supports the distribution of events from the application to Sources so that the /// Source can maintain its user interface and return messages to the application. Once the /// application has enabled the Source, it must immediately begin sending to the Source all events /// that enter the application’s main event loop. This allows the Source to update its user interface /// in real-time and to return messages to the application which cause state transitions. Even if the /// application overrides the Source’s user interface, it must forward all events once the Source has /// been enabled. The Source will tell the application whether or not each event belongs to the /// Source. /// </summary> /// <param name="theEvent">The event.</param> /// <returns></returns> public ReturnCode ProcessEvent(TWEvent theEvent) { Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Event, Message.ProcessEvent); return(Dsm.DsmEntry(Session.AppId, Session.CurrentSource.Identity, Message.ProcessEvent, theEvent)); }