2014-04-05 19:39:41 -04:00
using NTwain.Data ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Security.Permissions ;
using System.Text ;
using System.Windows.Forms ;
namespace NTwain
{
/// <summary>
/// A customized TWAIN session for use in WPF environment.
/// Use this by using <see cref="PreFilterMessage"/> method as the target of <see cref="HwndSource.AddHook"/> delegate.
/// </summary>
public class TwainSessionWPF : TwainSessionBase
{
/// <summary>
/// Initializes a new instance of the <see cref="TwainSessionWPF" /> class.
/// </summary>
/// <param name="appId">The app id.</param>
/// <exception cref="System.ArgumentNullException"></exception>
public TwainSessionWPF ( TWIdentity appId ) : base ( appId ) { }
/// <summary>
/// Message loop processor for WPF.
/// </summary>
/// <param name="hwnd">The window handle.</param>
/// <param name="msg">The message ID.</param>
/// <param name="wParam">The message's wParam value.</param>
/// <param name="lParam">The message's lParam value.</param>
/// <param name="handled">A value that indicates whether the message was handled. Set the value to true if the message was handled; otherwise, false.</param>
/// <returns></returns>
[EnvironmentPermissionAttribute(SecurityAction.LinkDemand)]
public IntPtr PreFilterMessage ( IntPtr hwnd , int msg , IntPtr wParam , IntPtr lParam , ref bool handled )
{
2014-04-05 20:30:49 -04:00
MESSAGE winmsg = default ( MESSAGE ) ;
2014-04-05 19:39:41 -04:00
winmsg . hwnd = hwnd ;
winmsg . lParam = lParam ;
2014-04-05 20:30:49 -04:00
winmsg . message = ( uint ) msg ;
2014-04-05 19:39:41 -04:00
winmsg . wParam = wParam ;
handled = base . HandleWndProcMessage ( ref winmsg ) ;
return IntPtr . Zero ;
}
}
}