title: Hiding scanner progress bar window
body: <p>I'm making an application that needs to scan an image, from a scanner.</p>
  
  <p>I've based my application on this project
  <a href="http://www.codeproject.com/Articles/171666/Twain-for-WPF-Applications-Look-Ma-No-Handles" rel="nofollow">http://www.codeproject.com/Articles/171666/Twain-for-WPF-Applications-Look-Ma-No-Handles</a>
  and the scanning part works excelently.</p>
  
  <p>But here is my problem: I need to make the scan without showing any window to the user.</p>
  
  <p>The above project allows me not to to display the scanner configuration option screen to the user,
  but it still displays the progress bar.</p>
  
  <p>The progress bar shows up (and the scan begins) when I call</p>
  
  <pre><code>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 );
  </code></pre>
  
  <p>I searched throughout all the parameters but was unable to see any that could disable the progress bar.</p>
  
  <p>So I decided to capture the event of the progress bar window being created, and hide it (is there any better way?) but the event isn't being caught.</p>
  
  <p>First I create a temporary window, because my application will be a windows service and also because TWAIN requires a window handle to which it associates the progress bar.</p>
  
  <p>This is my code</p>
  
  <pre><code>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();
  </code></pre>
  
  <p>I receive the event of my tmpWindow being created but not the progress bar. What am I missing here?</p>
  
  <p>*<strong>EDIT : *</strong> Had forgotten to add my hook function in this post</p>
  
  <pre><code>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;
  }
  </code></pre>