0

I am working with a Finger Print Sensor by ZkTeco. The below code in WFA works fine and the input from Finger Print Sensor is captured successfully.

   protected override void DefWndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case MESSAGE_CAPTURED_OK:
                {
                    MemoryStream ms = new MemoryStream();
                    BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms);
                    Bitmap bmp = new Bitmap(ms);
                    this.picFPImg.Image = bmp;
                    if (IsRegister)
                    {  
                      // Logic here  
                    }
                 }
          }
            default:
                base.DefWndProc(ref m);
                break;
      }  

But the alternative in WPF below code doesn't work.

    HwndSource source;
    protected override void OnSourceInitialized(EventArgs e)
    {
        var window = Application.Current.MainWindow;

        base.OnSourceInitialized(e);
        if (window != null)
        {
            HwndSource source = PresentationSource.FromVisual(window) as HwndSource;

            source?.AddHook(WndProc);
        }
    }
   private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        switch (msg)
        {
            case MESSAGE_CAPTURED_OK:
                {
                    MemoryStream ms = new MemoryStream();
                    BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms);
                 }
         }
     }  

While Debugging the function is being called but the Switch statement MESSAGE_CAPTURED_OK never becomes true. What could be the reason ?

Hammas_Stack1
  • 184
  • 1
  • 13
  • Are you sure MESSAGE_CAPTURED_OK is defined correctly? Are you sure the Application.Current.MainWindow is the correct window you want to hook the WndProc for? – Jeff R. Feb 25 '19 at 20:50
  • @JeffR. Yes i am sure MESSAGE_CAPTURED_OK is defined correctly and yes MainWindow is the window which contains some kind of functionality and all above code is written in that MainWindow.cs file . So yeah ! and also the code works fine in WFA (wfa version). – Hammas_Stack1 Feb 26 '19 at 10:15

0 Answers0