mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
More update for internal loop handling.
This commit is contained in:
parent
d8512f7706
commit
3ae070e3a3
@ -12,8 +12,8 @@ namespace NTwain
|
||||
class _NTwainVersionInfo
|
||||
{
|
||||
// keep this same in majors releases
|
||||
public const string Release = "0.10.0.0";
|
||||
public const string Release = "0.11.0.0";
|
||||
// change this for each nuget release
|
||||
public const string Build = "0.10.2";
|
||||
public const string Build = "0.11.0";
|
||||
}
|
||||
}
|
@ -32,8 +32,6 @@ namespace NTwain
|
||||
((ITwainStateInternal)this).ChangeState(1, false);
|
||||
EnforceState = true;
|
||||
|
||||
Debug.WriteLine("current thread id =" + Thread.CurrentThread.ManagedThreadId);
|
||||
|
||||
MessageLoop.Instance.EnsureStarted();
|
||||
}
|
||||
|
||||
@ -298,8 +296,6 @@ namespace NTwain
|
||||
rc = DGControl.Identity.CloseDS();
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
MessageLoop.Instance.RemoveHook(HandleWndProcMessage);
|
||||
_callbackObj = null;
|
||||
SupportedCaps = null;
|
||||
}
|
||||
});
|
||||
@ -385,6 +381,14 @@ namespace NTwain
|
||||
rc = DGControl.UserInterface.DisableDS(_twui);
|
||||
if (rc == ReturnCode.Success)
|
||||
{
|
||||
if (_callbackObj == null)
|
||||
{
|
||||
MessageLoop.Instance.RemoveHook(HandleWndProcMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
_callbackObj = null;
|
||||
}
|
||||
OnSourceDisabled();
|
||||
}
|
||||
});
|
||||
@ -418,26 +422,29 @@ namespace NTwain
|
||||
// success, the return status from DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER may
|
||||
// be ignored.
|
||||
|
||||
if (targetState < 7)
|
||||
MessageLoop.Instance.Invoke(() =>
|
||||
{
|
||||
DGControl.PendingXfers.EndXfer(new TWPendingXfers());
|
||||
}
|
||||
if (targetState < 6)
|
||||
{
|
||||
DGControl.PendingXfers.Reset(new TWPendingXfers());
|
||||
}
|
||||
if (targetState < 5)
|
||||
{
|
||||
DisableSource();
|
||||
}
|
||||
if (targetState < 4)
|
||||
{
|
||||
CloseSource();
|
||||
}
|
||||
if (targetState < 3)
|
||||
{
|
||||
CloseManager();
|
||||
}
|
||||
if (targetState < 7)
|
||||
{
|
||||
DGControl.PendingXfers.EndXfer(new TWPendingXfers());
|
||||
}
|
||||
if (targetState < 6)
|
||||
{
|
||||
DGControl.PendingXfers.Reset(new TWPendingXfers());
|
||||
}
|
||||
if (targetState < 5)
|
||||
{
|
||||
DisableSource();
|
||||
}
|
||||
if (targetState < 4)
|
||||
{
|
||||
CloseSource();
|
||||
}
|
||||
if (targetState < 3)
|
||||
{
|
||||
CloseManager();
|
||||
}
|
||||
});
|
||||
EnforceState = origFlag;
|
||||
}
|
||||
|
||||
@ -601,12 +608,10 @@ namespace NTwain
|
||||
IntPtr HandleWndProcMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
// this handles the message from a typical WndProc message loop and check if it's from the TWAIN source.
|
||||
|
||||
var winmsg = new MESSAGE(hwnd, msg, wParam, lParam);
|
||||
|
||||
if (State >= 4) // technically we should only handle on state >= 5 but there might be missed msgs if we wait until state changes after enabling ds
|
||||
if (State >= 5)
|
||||
{
|
||||
// transform it into a pointer for twain
|
||||
var winmsg = new MESSAGE(hwnd, msg, wParam, lParam);
|
||||
IntPtr msgPtr = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
@ -614,7 +619,7 @@ namespace NTwain
|
||||
msgPtr = Marshal.AllocHGlobal(Marshal.SizeOf(winmsg));
|
||||
Marshal.StructureToPtr(winmsg, msgPtr, false);
|
||||
|
||||
TWEvent evt = new TWEvent();
|
||||
var evt = new TWEvent();
|
||||
evt.pEvent = msgPtr;
|
||||
if (handled = (DGControl.Event.ProcessEvent(evt) == ReturnCode.DSEvent))
|
||||
{
|
||||
|
@ -4,13 +4,13 @@ TWAIN Application-Side Library
|
||||
Info
|
||||
--------------------------------------
|
||||
This is a dotnet library created to work with [TWAIN](http://twain.org/) interface.
|
||||
This project follows these general goals:
|
||||
This project has these features:
|
||||
|
||||
* Targets latest TWAIN version (2.3 at the moment)
|
||||
* Supports all the TWAIN functions in the spec
|
||||
* Eventally work on platforms other than Windows (I can dream)
|
||||
* Hosts internal message loop so no need to hook into application UI thread
|
||||
|
||||
The solution contains sample projects in winforms, wpf, and even (gasp!) console.
|
||||
The solution contains tester projects in winform, wpf, and even (gasp!) console.
|
||||
A nuget package is also [available here](https://www.nuget.org/packages/ntwain)
|
||||
|
||||
Using the lib
|
||||
@ -22,4 +22,7 @@ when and how to use them. There are no high-level, single-line scan-a-page-for-m
|
||||
|
||||
At the moment this lib does not provide ways to parse transferred image data and require
|
||||
consumers to do the conversion. The winform project contains one such
|
||||
example for handling DIB image in native transfer.
|
||||
example for handling DIB image in native transfer.
|
||||
|
||||
The main class to use is TwainSession. New it up, hook into the events, and start calling
|
||||
all the TWAIN functions provided through it.
|
@ -19,7 +19,7 @@ namespace Tester
|
||||
{
|
||||
// just an amusing example to do twain in console without UI
|
||||
DoTwainWork();
|
||||
Console.WriteLine("Test completed, press Enter to exit.");
|
||||
Console.WriteLine("Test started, press Enter to exit.");
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
|
@ -345,7 +345,7 @@ namespace Tester.Winform
|
||||
{
|
||||
if (!_loadingCaps && _twain.State == 4)
|
||||
{
|
||||
var sel = (int)comboDPI.SelectedItem;
|
||||
var sel = (TWFix32)comboDPI.SelectedItem;
|
||||
_twain.CapSetDPI(sel);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user