mirror of
https://github.com/soukoku/ntwain.git
synced 2025-11-08 02:24:46 +08:00
msg loop tweaks & intptr cleanup.
This commit is contained in:
@@ -45,6 +45,7 @@ namespace NTwain.Internals
|
||||
{
|
||||
_hook.Dispose();
|
||||
_hook = null;
|
||||
Handle = IntPtr.Zero;
|
||||
}
|
||||
}));
|
||||
loopThread.IsBackground = true;
|
||||
|
||||
@@ -24,4 +24,11 @@ namespace NTwain.Internals
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
static class NativeMethods
|
||||
{
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Interop;
|
||||
|
||||
@@ -18,13 +19,13 @@ namespace NTwain.Internals
|
||||
{
|
||||
_filter = filter;
|
||||
|
||||
// hook into windows msg loop for old twain to post msgs.
|
||||
// the style values are purely guesses here with
|
||||
// CS_NOCLOSE, WS_DISABLED, and WS_EX_NOACTIVATE
|
||||
HwndSource win = null;
|
||||
try
|
||||
{
|
||||
win = new HwndSource(0x0200, 0x8000000, 0x8000000, 0, 0, "NTWAIN_LOOPER", IntPtr.Zero);
|
||||
// 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;
|
||||
@@ -43,6 +44,13 @@ namespace NTwain.Internals
|
||||
{
|
||||
handled = _filter.IsTwainMessage(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
if (!handled)
|
||||
{
|
||||
Debug.WriteLine("Hwnd=" + hwnd);
|
||||
handled = true;
|
||||
// unnecessary to do default wndproc?
|
||||
return NativeMethods.DefWindowProc(hwnd, (uint)msg, wParam, lParam);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
@@ -58,6 +66,7 @@ namespace NTwain.Internals
|
||||
((HwndSource)_win).RemoveHook(WndProc);
|
||||
_win.Dispose();
|
||||
_win = null;
|
||||
Handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ namespace NTwain
|
||||
//{
|
||||
System.Windows.Forms.Application.RemoveMessageFilter(this);
|
||||
_filter = null;
|
||||
Handle = IntPtr.Zero;
|
||||
//});
|
||||
}
|
||||
|
||||
@@ -192,6 +193,7 @@ namespace NTwain
|
||||
_hooker.RemoveHook(FilterMessage);
|
||||
_hooker.Dispose();
|
||||
_hooker = null;
|
||||
Handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@ namespace NTwain
|
||||
// keep this same in majors releases
|
||||
public const string Release = "2.0.0.0";
|
||||
// change this for each nuget release
|
||||
public const string Build = "2.0.6";
|
||||
public const string Build = "2.0.7";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user