隐藏扫描仪进度条窗口

时间:2012-04-11 11:05:29

标签: c# winforms winapi events hook

我正在制作一个需要从扫描仪扫描图像的应用程序。

我的申请基于这个项目 http://www.codeproject.com/Articles/171666/Twain-for-WPF-Applications-Look-Ma-No-Handles 扫描部分工作得非常好。

但这是我的问题:我需要进行扫描而不向用户显示任何窗口。

上述项目允许我不向用户显示扫描仪配置选项屏幕, 但它仍然显示进度条。

当我拨打

时,进度条显示(并开始扫描)
DSixfer(
    appid,
    srcds,
    TwDG.Image,
    TwDAT.ImageNativeXfer,
    TwMSG.Get,
    ref hbitmap );

[DllImport("twain_32.dll", EntryPoint="#1")]
private static extern TwRC DSixfer( [In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, ref IntPtr hbitmap );

我搜索了所有参数,但无法看到任何可能会禁用进度条的内容。

所以我决定捕获正在创建的进度条窗口的事件,然后隐藏它(有没有更好的方法?)但事件没有被捕获。

首先我创建一个临时窗口,因为我的应用程序将是一个Windows服务,并且因为TWAIN需要一个与进度条关联的窗口句柄。

这是我的代码

HookProc WindowCreationProcedure = new HookProc(WindowCreationHookProc);

int hHook = SetWindowsHookEx(WH_SHELL,
        WindowCreationProcedure,
        (IntPtr)0,
        AppDomain.GetCurrentThreadId()
        );

System.Windows.Window tmpWindow = new System.Windows.Window();
tmpWindow.WindowState = WindowState.Minimized;  //So that the window isn't showed
tmpWindow.Show();

我收到了创建tmpWindow的事件,但没有收到进度条。我在这里缺少什么?

* 编辑:* 我忘了在这篇文章中添加我的钩子功能

private const int WH_SHELL = 10;
private const int HSHELL_WINDOWCREATED = 1;

public static int WindowCreationHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
    if (nCode == HSHELL_WINDOWCREATED)
    {
        Console.WriteLine("WINDOW CREATED");
        return 1;
    }
    return 0;
}

1 个答案:

答案 0 :(得分:0)

要阻止TWAIN弹出它的界面,您需要使用ShowUI = FALSE和ModalUI = FALSE发送消息DG_CONTROL / DAT_USERINTERFACE / MSG_ENABLEDS。这是some example code

也可以在扫描期间获得增量状态,而不是在整个扫描期间被阻止。您可以使用内存块传输,而不是使用ImageNativeXfer,从Twain Spec的第4-20页开始介绍。您可以看到example code here