mirror of
https://github.com/soukoku/ntwain.git
synced 2025-11-08 10:34:47 +08:00
First changeset to make internal message loop non-global.
This commit is contained in:
@@ -13,10 +13,12 @@ namespace NTwain.Internals
|
||||
class WindowsHook : IDisposable
|
||||
{
|
||||
IDisposable _win;
|
||||
WndProcHook _hook;
|
||||
IWinMessageFilter _filter;
|
||||
|
||||
public WindowsHook(WndProcHook hook)
|
||||
public WindowsHook(IWinMessageFilter filter)
|
||||
{
|
||||
_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
|
||||
@@ -27,7 +29,6 @@ namespace NTwain.Internals
|
||||
Handle = win.Handle;
|
||||
win.AddHook(WndProc);
|
||||
_win = win;
|
||||
_hook = hook;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -36,15 +37,12 @@ namespace NTwain.Internals
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void WndProcHook(ref MESSAGE winMsg, ref bool handled);
|
||||
|
||||
|
||||
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
if (_hook != null)
|
||||
if (_filter != null)
|
||||
{
|
||||
var winmsg = new MESSAGE(hwnd, msg, wParam, lParam);
|
||||
_hook(ref winmsg, ref handled);
|
||||
handled = _filter.IsTwainMessage(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
@@ -52,32 +50,6 @@ namespace NTwain.Internals
|
||||
public IntPtr Handle { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The MSG structure in Windows for TWAIN use.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MESSAGE
|
||||
{
|
||||
public MESSAGE(IntPtr hwnd, int message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
_hwnd = hwnd;
|
||||
_message = (uint)message;
|
||||
_wParam = wParam;
|
||||
_lParam = lParam;
|
||||
_time = 0;
|
||||
_x = 0;
|
||||
_y = 0;
|
||||
}
|
||||
|
||||
IntPtr _hwnd;
|
||||
uint _message;
|
||||
IntPtr _wParam;
|
||||
IntPtr _lParam;
|
||||
uint _time;
|
||||
int _x;
|
||||
int _y;
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
|
||||
Reference in New Issue
Block a user