mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +08:00
Added winform/wpf reg methods
This commit is contained in:
@@ -67,7 +67,7 @@ namespace NTwain
|
||||
/// <returns></returns>
|
||||
public STS SetDefaultSource(TW_IDENTITY_LEGACY source)
|
||||
{
|
||||
// TODO: this doesn't work???
|
||||
// this doesn't work on windows legacy twain_32.dll
|
||||
|
||||
var rc = DGControl.Identity.Set(ref _appIdentity, ref source);
|
||||
if (rc == STS.SUCCESS)
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Interop;
|
||||
using MSG = NTwain.Data.MSG;
|
||||
|
||||
namespace NTwain
|
||||
{
|
||||
@@ -15,14 +17,53 @@ namespace NTwain
|
||||
|
||||
partial class TwainSession : IMessageFilter
|
||||
{
|
||||
// winform use with Application.AddMessageFilter(<TwainSession instance>)
|
||||
private HwndSource? _wpfhook;
|
||||
|
||||
/// <summary>
|
||||
/// Registers this session for use in a Winform UI thread.
|
||||
/// </summary>
|
||||
public void AddWinformFilter()
|
||||
{
|
||||
Application.AddMessageFilter(this);
|
||||
}
|
||||
/// <summary>
|
||||
/// Unregisters this session if previously registered with <see cref="AddWinformFilter"/>.
|
||||
/// </summary>
|
||||
public void RemoveWinformFilter()
|
||||
{
|
||||
Application.RemoveMessageFilter(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers this session for use in a WPF UI thread.
|
||||
/// </summary>
|
||||
public void AddWpfHook()
|
||||
{
|
||||
if (_wpfhook == null)
|
||||
{
|
||||
_wpfhook = HwndSource.FromHwnd(_hwnd);
|
||||
_wpfhook.AddHook(WpfHook);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Unregisters this session if previously registered with <see cref="AddWpfHook"/>.
|
||||
/// </summary>
|
||||
public void RemoveWpfHook()
|
||||
{
|
||||
if (_wpfhook != null)
|
||||
{
|
||||
_wpfhook.RemoveHook(WpfHook);
|
||||
_wpfhook = null;
|
||||
}
|
||||
}
|
||||
|
||||
bool System.Windows.Forms.IMessageFilter.PreFilterMessage(ref System.Windows.Forms.Message m)
|
||||
{
|
||||
return CheckIfTwainMessage(m.HWnd, m.Msg, m.WParam, m.LParam);
|
||||
}
|
||||
|
||||
// wpf use
|
||||
IntPtr HwndSourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
// wpf use with HwndSource.FromHwnd(Handle).AddHook(
|
||||
IntPtr WpfHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
handled = CheckIfTwainMessage(hwnd, msg, wParam, lParam);
|
||||
return IntPtr.Zero;
|
||||
@@ -32,7 +73,7 @@ namespace NTwain
|
||||
{
|
||||
// this handles the message from a typical WndProc message loop and check if it's from the TWAIN source.
|
||||
bool handled = false;
|
||||
if (_state >= Data.STATE.S5)
|
||||
if (_state >= STATE.S5)
|
||||
{
|
||||
TW_EVENT evt = default;
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user