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

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