msg loop tweaks & intptr cleanup.

This commit is contained in:
soukoku
2014-09-05 06:56:57 -04:00
parent 19f65642b2
commit 669de30345
8 changed files with 26 additions and 9 deletions

View File

@@ -45,6 +45,7 @@ namespace NTwain.Internals
{
_hook.Dispose();
_hook = null;
Handle = IntPtr.Zero;
}
}));
loopThread.IsBackground = true;

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -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";
}
}